From 1dcebd65dd65955716a657c625e1671256ad262b Mon Sep 17 00:00:00 2001 From: mentola Date: Fri, 6 Oct 2023 23:09:20 +0300 Subject: [PATCH] changed click method fix perfomance bug --- Easyyyyy/Core/Mouse.cs | 47 ++++++---------------------- Easyyyyy/Properties/AssemblyInfo.cs | 4 +-- Easyyyyy/ViewModels/MainViewModel.cs | 16 ++++++---- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/Easyyyyy/Core/Mouse.cs b/Easyyyyy/Core/Mouse.cs index 91d5a4b..7b4c676 100644 --- a/Easyyyyy/Core/Mouse.cs +++ b/Easyyyyy/Core/Mouse.cs @@ -1,6 +1,4 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows; +using System.Runtime.InteropServices; namespace Easyyyyy.Core { @@ -17,41 +15,16 @@ private enum MouseEvent MOUSEEVENTF_RIGHTUP = 0x10, } - [StructLayout(LayoutKind.Sequential)] - public struct POINT - { - public int X; - public int Y; - - public static implicit operator Point(POINT point) - { - return new Point(point.X, point.Y); - } - } - - [DllImport("user32.dll")] - public static extern bool GetCursorPos(out POINT lpPoint); - - public static Point GetCursorPosition() - { - POINT lpPoint; - GetCursorPos(out lpPoint); - - return lpPoint; - } - public void oneClick(bool isLeftClick) { - var cursorPosition = GetCursorPosition(); - if (isLeftClick) { - mouse_event(MouseEvent.MOUSEEVENTF_LEFTDOWN, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); - mouse_event(MouseEvent.MOUSEEVENTF_LEFTUP, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } else { - mouse_event(MouseEvent.MOUSEEVENTF_RIGHTDOWN, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); - mouse_event(MouseEvent.MOUSEEVENTF_RIGHTUP, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); } } @@ -59,16 +32,14 @@ public void doubleClick(bool isLeftClick) { for (int x = 0; x != 2; x++) { - var cursorPosition = GetCursorPosition(); - if (isLeftClick) { - mouse_event(MouseEvent.MOUSEEVENTF_LEFTDOWN, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); - mouse_event(MouseEvent.MOUSEEVENTF_LEFTUP, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } else { - mouse_event(MouseEvent.MOUSEEVENTF_RIGHTDOWN, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); - mouse_event(MouseEvent.MOUSEEVENTF_RIGHTUP, Convert.ToInt32(cursorPosition.X), Convert.ToInt32(cursorPosition.Y), 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); + mouse_event(MouseEvent.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); } } } diff --git a/Easyyyyy/Properties/AssemblyInfo.cs b/Easyyyyy/Properties/AssemblyInfo.cs index 3cfd63d..ff0cac2 100644 --- a/Easyyyyy/Properties/AssemblyInfo.cs +++ b/Easyyyyy/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.0")] -[assembly: AssemblyFileVersion("1.0.2.0")] +[assembly: AssemblyVersion("1.0.2.1")] +[assembly: AssemblyFileVersion("1.0.2.1")] diff --git a/Easyyyyy/ViewModels/MainViewModel.cs b/Easyyyyy/ViewModels/MainViewModel.cs index 3bd20b4..d0d757c 100644 --- a/Easyyyyy/ViewModels/MainViewModel.cs +++ b/Easyyyyy/ViewModels/MainViewModel.cs @@ -287,6 +287,10 @@ private void runAutoClicker() while (true) { + int timeToWait = 0; + if (isEnabledRandom && countCPS > 5) timeToWait = (1000 / new Random().Next(countCPS - ((countCPS / 100) * 25), countCPS)); + else timeToWait = (1000 / countCPS); + if (isToggleMode) { isEnabled = isToggleEnabled; @@ -302,6 +306,8 @@ private void runAutoClicker() { mouse.doubleClick(isLeftClick); } + + Thread.Sleep(timeToWait); } } else @@ -319,6 +325,8 @@ private void runAutoClicker() { mouse.doubleClick(isLeftClick); } + + Thread.Sleep(timeToWait); } else { @@ -331,11 +339,7 @@ private void runAutoClicker() break; } - int timeToWait = 0; - if (!isEnabledRandom) timeToWait = 1000 / countCPS; - else if (countCPS > 5) timeToWait = 1000 / new Random().Next(countCPS - ((countCPS / 100) * 20), countCPS); - - Thread.Sleep(timeToWait); + Thread.Sleep(1); } if (Application.Current != null) @@ -355,7 +359,7 @@ private void eToggleMode() { isToggleEnabled = !isToggleEnabled; // delay - Thread.Sleep(250); + Thread.Sleep(150); } if (isStopped)