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

Commit

Permalink
changed click function
Browse files Browse the repository at this point in the history
  • Loading branch information
mentolaass committed Oct 7, 2023
1 parent 1dcebd6 commit baa4d25
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 79 deletions.
51 changes: 51 additions & 0 deletions Easyyyyy/Core/Click.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
13 changes: 1 addition & 12 deletions Easyyyyy/Core/Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions Easyyyyy/Core/Win32.cs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
2 changes: 2 additions & 0 deletions Easyyyyy/Easyyyyy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Binding.cs" />
<Compile Include="Core\Click.cs" />
<Compile Include="Core\Mouse.cs" />
<Compile Include="Core\Win32.cs" />
<Compile Include="Models\Configuration.cs" />
<Compile Include="Models\RelayCommand.cs" />
<Compile Include="ViewModels\BaseViewModel.cs" />
Expand Down
88 changes: 22 additions & 66 deletions Easyyyyy/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Easyyyyy/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</i:EventTrigger>

<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding updateValues}" />
<i:InvokeCommandAction Command="{Binding startLoops}" />
</i:EventTrigger>
</i:Interaction.Triggers>

Expand Down

0 comments on commit baa4d25

Please sign in to comment.