-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutoClickerDriver.cs
More file actions
190 lines (166 loc) · 6.02 KB
/
AutoClickerDriver.cs
File metadata and controls
190 lines (166 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Timers;
namespace AutoClicker
{
class AutoClickerDriver
{
//Set the cursor position
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);
//Mouse event method to be called with parameters for mouse functions
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
//Mouse left click values
private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
//Mouse middle click values
private const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
private const int MOUSEEVENTF_MIDDLEUP = 0x0040;
//Mouse right click values
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const int MOUSEEVENTF_RIGHTUP = 0x0010;
private int TotalMilliseconds;
private System.Timers.Timer TickTimer;
private int MouseButton, ClickType, NumberOfClicks;
private Point CursorPosition;
private Boolean ActivePosition, SetPosition, Slider, ManualEntry;
//Manual Entry Constructor
public AutoClickerDriver(int TotalMilliseconds, int MouseButton, int ClickType, Point CursorPosition, Boolean ActivePosition, Boolean SetPosition, Boolean Slider, Boolean ManualEntry)
{
this.TotalMilliseconds = TotalMilliseconds;
this.MouseButton = MouseButton;
this.ClickType = ClickType;
this.CursorPosition = CursorPosition;
this.ActivePosition = ActivePosition;
this.SetPosition = SetPosition;
this.Slider = Slider;
this.ManualEntry = ManualEntry;
if(this.ClickType == 0)
{
this.NumberOfClicks = 1;
}
else if(this.ClickType == 1)
{
this.NumberOfClicks = 2;
}
if (this.ActivePosition)
{
this.TickTimer = new System.Timers.Timer(this.TotalMilliseconds);
this.TickTimer.Elapsed += ActivePositionTick;
this.TickTimer.Start();
}
else if (this.SetPosition)
{
this.TickTimer = new System.Timers.Timer(this.TotalMilliseconds);
this.TickTimer.Elapsed += SetPositionTick;
this.TickTimer.Start();
}
}
private void ActivePositionTick(Object source, ElapsedEventArgs e)
{
if (!AutoClicker.ClickerEnabled)
{
this.TickTimer.Stop();
}
switch (this.MouseButton)
{
//Left Click
case 0:
for(int i = 0; i < this.NumberOfClicks; i++)
{
LeftClick();
}
break;
//Middle Click
case 1:
for (int i = 0; i < this.NumberOfClicks; i++)
{
MiddleClick();
}
break;
//Right Click
case 2:
for (int i = 0; i < this.NumberOfClicks; i++)
{
RightClick();
}
break;
}
}
private void SetPositionTick(Object source, ElapsedEventArgs e)
{
if (!AutoClicker.ClickerEnabled)
{
this.TickTimer.Stop();
}
switch (this.MouseButton)
{
//Left Click
case 0:
for (int i = 0; i < this.NumberOfClicks; i++)
{
PosLeftClick(this.CursorPosition.X, this.CursorPosition.Y);
}
break;
//Middle Click
case 1:
for (int i = 0; i < this.NumberOfClicks; i++)
{
PosMiddleClick(this.CursorPosition.X, this.CursorPosition.Y);
}
break;
//Right Click
case 2:
for (int i = 0; i < this.NumberOfClicks; i++)
{
PosRightClick(this.CursorPosition.X, this.CursorPosition.Y);
}
break;
}
}
//Left click the mouse
private static void LeftClick()
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
//Middle click the mouse
private static void MiddleClick()
{
mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
}
//Right click the mouse
private static void RightClick()
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
private void PosLeftClick(int x, int y)
{
SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
private void PosMiddleClick(int x, int y)
{
SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_MIDDLEDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_MIDDLEUP, x, y, 0, 0);
}
private void PosRightClick(int x, int y)
{
SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
}
}
}