From baa4d25ede4a74e737a706232661eed271df32d0 Mon Sep 17 00:00:00 2001 From: mentola Date: Sat, 7 Oct 2023 15:05:26 +0300 Subject: [PATCH] changed click function --- Easyyyyy/Core/Click.cs | 51 ++++++++++++++++ Easyyyyy/Core/Mouse.cs | 13 +--- Easyyyyy/Core/Win32.cs | 21 +++++++ Easyyyyy/Easyyyyy.csproj | 2 + Easyyyyy/ViewModels/MainViewModel.cs | 88 +++++++--------------------- Easyyyyy/Views/MainWindow.xaml | 2 +- 6 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 Easyyyyy/Core/Click.cs create mode 100644 Easyyyyy/Core/Win32.cs diff --git a/Easyyyyy/Core/Click.cs b/Easyyyyy/Core/Click.cs new file mode 100644 index 0000000..00e3145 --- /dev/null +++ b/Easyyyyy/Core/Click.cs @@ -0,0 +1,51 @@ +using System.Threading; +using System.Windows.Input; +using System; + +namespace Easyyyyy.Core +{ + class Click + { + + public static void execClick(int countCPS, bool isEnabledRandom, bool isToggleEnabled, bool isLeftClick, bool isDefaultClicks, bool isToggleMode) + { + int timeToWait = 0; + if (isEnabledRandom && countCPS > 5) timeToWait = (1000 / new Random().Next(countCPS - ((countCPS / 100) * 25), countCPS)); + else timeToWait = (1000 / countCPS); + + var mouse = new Core.Mouse(); + + if (isToggleMode) + { + if (isToggleEnabled) + { + // if double click + if (isDefaultClicks) + { + mouse.oneClick(isLeftClick); + } + else + { + mouse.doubleClick(isLeftClick); + } + } + + Thread.Sleep(timeToWait); + } + else + { + // if double click + if (isDefaultClicks) + { + mouse.oneClick(isLeftClick); + } + else + { + mouse.doubleClick(isLeftClick); + } + + Thread.Sleep(timeToWait); + } + } + } +} diff --git a/Easyyyyy/Core/Mouse.cs b/Easyyyyy/Core/Mouse.cs index 7b4c676..8f438dd 100644 --- a/Easyyyyy/Core/Mouse.cs +++ b/Easyyyyy/Core/Mouse.cs @@ -2,19 +2,8 @@ namespace Easyyyyy.Core { - public class Mouse + public class Mouse : Win32 { - [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] - private static extern void mouse_event(MouseEvent dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); - - private enum MouseEvent - { - MOUSEEVENTF_LEFTDOWN = 0x02, - MOUSEEVENTF_LEFTUP = 0x04, - MOUSEEVENTF_RIGHTDOWN = 0x08, - MOUSEEVENTF_RIGHTUP = 0x10, - } - public void oneClick(bool isLeftClick) { if (isLeftClick) diff --git a/Easyyyyy/Core/Win32.cs b/Easyyyyy/Core/Win32.cs new file mode 100644 index 0000000..6d06091 --- /dev/null +++ b/Easyyyyy/Core/Win32.cs @@ -0,0 +1,21 @@ +using System.Runtime.InteropServices; + +namespace Easyyyyy.Core +{ + public class Win32 + { + [DllImport("User32.dll")] + public static extern bool GetAsyncKeyState(int vKey); + + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + public static extern void mouse_event(MouseEvent dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); + + public enum MouseEvent + { + MOUSEEVENTF_LEFTDOWN = 0x02, + MOUSEEVENTF_LEFTUP = 0x04, + MOUSEEVENTF_RIGHTDOWN = 0x08, + MOUSEEVENTF_RIGHTUP = 0x10, + } + } +} diff --git a/Easyyyyy/Easyyyyy.csproj b/Easyyyyy/Easyyyyy.csproj index 49b2605..9e02347 100644 --- a/Easyyyyy/Easyyyyy.csproj +++ b/Easyyyyy/Easyyyyy.csproj @@ -232,7 +232,9 @@ Code + + diff --git a/Easyyyyy/ViewModels/MainViewModel.cs b/Easyyyyy/ViewModels/MainViewModel.cs index d0d757c..ea44b5a 100644 --- a/Easyyyyy/ViewModels/MainViewModel.cs +++ b/Easyyyyy/ViewModels/MainViewModel.cs @@ -1,12 +1,9 @@ -using Easyyyyy.Models; -using System; +using Easyyyyy.Core; +using Easyyyyy.Models; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Threading; -using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -using System.Windows.Media.Animation; namespace Easyyyyy.ViewModels { @@ -263,82 +260,43 @@ public RelayCommand openGithub }); } - public RelayCommand updateValues + public RelayCommand startLoops { get => new RelayCommand(obj => { - eToggleMode(); - runAutoClicker(); + loopToggleMode(); + loopAutoClick(); }); } - [DllImport("User32.dll")] - public static extern bool GetAsyncKeyState(int vKey); private bool isStopped = false; private bool isToggleEnabled = false; - private void runAutoClicker() + private void loopAutoClick() { new Thread(() => { - var mouse = new Core.Mouse(); - while (true) { - int timeToWait = 0; - if (isEnabledRandom && countCPS > 5) timeToWait = (1000 / new Random().Next(countCPS - ((countCPS / 100) * 25), countCPS)); - else timeToWait = (1000 / countCPS); + if (isStopped) + break; - if (isToggleMode) + if (Win32.GetAsyncKeyState(intBindKey)) { - isEnabled = isToggleEnabled; - - if (isToggleEnabled) - { - // if double click - if (isDefaultClicks) - { - mouse.oneClick(isLeftClick); - } - else - { - mouse.doubleClick(isLeftClick); - } - - Thread.Sleep(timeToWait); - } - } - else + Click.execClick(countCPS, isEnabledRandom, isToggleEnabled, isLeftClick, isDefaultClicks, isToggleMode); + isEnabled = true; + } else if (isToggleEnabled) { - if (GetAsyncKeyState(intBindKey)) - { - isEnabled = true; - - // if double click - if (isDefaultClicks) - { - mouse.oneClick(isLeftClick); - } - else - { - mouse.doubleClick(isLeftClick); - } - - Thread.Sleep(timeToWait); - } - else - { - isEnabled = false; - } - } - - if (isStopped) + Click.execClick(countCPS, isEnabledRandom, isToggleEnabled, isLeftClick, isDefaultClicks, isToggleMode); + isEnabled = true; + } else { - break; + isEnabled = false; } + Thread.Sleep(1); } @@ -349,25 +307,23 @@ private void runAutoClicker() }).Start(); } - private void eToggleMode() + private void loopToggleMode() { new Thread(() => { - while(true) + while (true) { - if (isToggleMode && GetAsyncKeyState(intBindKey)) + if (isToggleMode && Win32.GetAsyncKeyState(intBindKey)) { isToggleEnabled = !isToggleEnabled; // delay - Thread.Sleep(150); + Thread.Sleep(500); } if (isStopped) - { break; - } - Thread.Sleep(1); + Thread.Sleep(5); } }).Start(); } diff --git a/Easyyyyy/Views/MainWindow.xaml b/Easyyyyy/Views/MainWindow.xaml index 200641c..4a5e739 100644 --- a/Easyyyyy/Views/MainWindow.xaml +++ b/Easyyyyy/Views/MainWindow.xaml @@ -29,7 +29,7 @@ - +