Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
changed click method
Browse files Browse the repository at this point in the history
fix perfomance bug
  • Loading branch information
mentolaass committed Oct 6, 2023
1 parent b7893d9 commit 1dcebd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
47 changes: 9 additions & 38 deletions Easyyyyy/Core/Mouse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Runtime.InteropServices;

namespace Easyyyyy.Core
{
Expand All @@ -17,58 +15,31 @@ 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);
}
}

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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Easyyyyy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
16 changes: 10 additions & 6 deletions Easyyyyy/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -302,6 +306,8 @@ private void runAutoClicker()
{
mouse.doubleClick(isLeftClick);
}
Thread.Sleep(timeToWait);
}
}
else
Expand All @@ -319,6 +325,8 @@ private void runAutoClicker()
{
mouse.doubleClick(isLeftClick);
}
Thread.Sleep(timeToWait);
}
else
{
Expand All @@ -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)
Expand All @@ -355,7 +359,7 @@ private void eToggleMode()
{
isToggleEnabled = !isToggleEnabled;
// delay
Thread.Sleep(250);
Thread.Sleep(150);
}
if (isStopped)
Expand Down

0 comments on commit 1dcebd6

Please sign in to comment.