-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutoClicker.cs
More file actions
468 lines (376 loc) · 14.7 KB
/
AutoClicker.cs
File metadata and controls
468 lines (376 loc) · 14.7 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoClicker
{
public partial class AutoClicker : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int RegisterHotKey(IntPtr hWnd, int id, uint modifier, uint vk);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
//ID for the F6, F7 Hotkey, used later to check which hotkey is being used
private const int F6HOTKEYID = 1;
private const int F7HOTKEYID = 2;
//Constant value for the hotkey value using WndProc
private const int WM_HOTKEY = 0x0312;
//Modifiers for Hotkey registry
private enum Modifiers
{
NONE = 0x0000,
ALT = 0x0001,
CONTROL = 0x0002,
SHIFT = 0x0004,
WINDOWS = 0x0008
}
//Separate thread to run the clicking operation
private Thread ClickerThread;
//Boolean to check if the clicker thread is running
public static Boolean ClickerEnabled = false;
//Mouse Speed Selectors
private Boolean Slider;
private Boolean ManualEntry;
//Mouse Position Selectors
private Boolean ActivePosition;
private Boolean SetPosition;
//Mouse Speed Options for manual entry
private int Hours;
private int Minutes;
private int Seconds;
private int Milliseconds;
//Slider Speed
private int SliderSpeed;
//Mouse Position Options
private int XPosition;
private int YPosition;
//Click Options
private int MouseButton;
private int ClickType;
//Cursor position point
private Point CursorPoint = new Point();
//Total Milliseconds for the timer
private int TotalMilliseconds;
//Constructor to start the window and set defaults
public AutoClicker()
{
InitializeComponent();
this.KeyPreview = true;
MouseButtonBox.SelectedIndex = 0;
MouseButtonBox.DropDownStyle = ComboBoxStyle.DropDownList;
ClickTypeBox.SelectedIndex = 0;
ClickTypeBox.DropDownStyle = ComboBoxStyle.DropDownList;
ActivePosRadio.Checked = true;
ManualRadio.Checked = true;
ClearButton.BackColor = Color.LightBlue;
StopButton.Enabled = false;
StopButton.BackColor = Color.Empty;
StartButton.BackColor = Color.LightGreen;
XPos.Enabled = false;
YPos.Enabled = false;
SpeedSlider.Enabled = false;
this.Slider = false;
this.ManualEntry = true;
this.ActivePosition = true;
this.SetPosition = false;
this.Hours = 0;
this.Minutes = 0;
this.Seconds = 0;
this.Milliseconds = 0;
this.SliderSpeed = 0;
this.XPosition = 0;
this.YPosition = 0;
this.MouseButton = 0;
this.ClickType = 0;
}
//Method to run when the Auto Clicker window loads
private void AutoClickerFormLoad(object sender, EventArgs e)
{
//Register the F6 hotkey with the system
RegisterHotKey(this.Handle, F6HOTKEYID, (uint)Modifiers.NONE, (uint)Keys.F6);
//Register the F7 hotkey with the system
RegisterHotKey(this.Handle, F7HOTKEYID, (uint)Modifiers.NONE, (uint)Keys.F7);
}
//Method to run when the Auto Clicker window closes
private void AutoClickerFormClose(object sender, FormClosedEventArgs e)
{
//Unregister the F6 hotkey with the system
UnregisterHotKey(this.Handle, F6HOTKEYID);
//Unregister the F7 hotkey with the system
UnregisterHotKey(this.Handle, F7HOTKEYID);
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
//Check for key down press
if(m.Msg == WM_HOTKEY)
{
//Switch over the ID assigned
switch (m.WParam.ToInt32())
{
case F6HOTKEYID:
if (ClickerEnabled == true)
{
StopButton.PerformClick();
}
else if (ClickerEnabled == false)
{
StartButton.PerformClick();
}
break;
case F7HOTKEYID:
if (ClickerEnabled == false && SetPosRadio.Checked)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
this.CursorPoint = new Point(Cursor.Position.X, Cursor.Position.Y);
this.XPosition = Cursor.Position.X;
this.YPosition = Cursor.Position.Y;
this.XPos.Text = Cursor.Position.X.ToString();
this.YPos.Text = Cursor.Position.Y.ToString();
}
break;
}
}
base.WndProc(ref m);
}
private Boolean CheckValues()
{
if (!String.IsNullOrWhiteSpace(MillisecondsBox.Text))
this.Milliseconds = Int32.Parse(MillisecondsBox.Text.ToString());
if (!String.IsNullOrWhiteSpace(SecondsBox.Text))
this.Seconds = Int32.Parse(SecondsBox.Text.ToString());
if (!String.IsNullOrWhiteSpace(MinutesBox.Text))
this.Minutes = Int32.Parse(MinutesBox.Text.ToString());
if (!String.IsNullOrWhiteSpace(HoursBox.Text))
this.Hours = Int32.Parse(HoursBox.Text.ToString());
if(this.Milliseconds > 0 || this.Seconds > 0 || this.Minutes > 0 || this.Hours > 0 || this.SliderSpeed > 0)
{
return true;
}
else
{
return false;
}
}
private Boolean CheckSetPosition()
{
if (this.SetPosition && !String.IsNullOrWhiteSpace(XPos.Text) && !String.IsNullOrWhiteSpace(YPos.Text))
{
if (!String.IsNullOrWhiteSpace(XPos.Text))
this.XPosition = Int32.Parse(XPos.Text.ToString());
if (!String.IsNullOrWhiteSpace(YPos.Text))
this.YPosition = Int32.Parse(YPos.Text.ToString());
this.CursorPoint.X = this.XPosition;
this.CursorPoint.Y = this.YPosition;
return true;
}
else if (this.ActivePosition)
{
return true;
}
return false;
}
private void StartAutoClicker(object sender, EventArgs e)
{
if(ClickerEnabled == false && CheckValues() && CheckSetPosition())
{
this.ActivePosition = ActivePosRadio.Checked;
this.SetPosition = SetPosRadio.Checked;
this.MouseButton = MouseButtonBox.SelectedIndex;
this.ClickType = ClickTypeBox.SelectedIndex;
ClickerThread = new Thread(new ThreadStart(AutoClickerEnableThread));
ClickerThread.Start();
ClickerEnabled = true;
StartButton.BackColor = Color.Empty;
StopButton.BackColor = Color.IndianRed;
ClearButton.BackColor = Color.Empty;
StartButton.Enabled = false;
StopButton.Enabled = true;
ClearButton.Enabled = false;
ManualRadio.Enabled = false;
SliderRadio.Enabled = false;
ActivePosRadio.Enabled = false;
SetPosRadio.Enabled = false;
if (ManualRadio.Checked)
{
HoursBox.Enabled = false;
MinutesBox.Enabled = false;
SecondsBox.Enabled = false;
MillisecondsBox.Enabled = false;
ManualRadio.Enabled = false;
SliderRadio.Enabled = false;
ActivePosRadio.Enabled = false;
SetPosRadio.Enabled = false;
MouseButtonBox.Enabled = false;
ClickTypeBox.Enabled = false;
if (SetPosRadio.Checked)
{
XPos.Enabled = false;
YPos.Enabled = false;
}
}
else if (SliderRadio.Checked)
{
SpeedSlider.Enabled = false;
MouseButtonBox.Enabled = false;
ClickTypeBox.Enabled = false;
if (SetPosRadio.Checked)
{
XPos.Enabled = false;
YPos.Enabled = false;
}
}
}
}
private void AutoClickerEnableThread()
{
if (this.ManualEntry)
{
this.TotalMilliseconds = Milliseconds + (Seconds * 1000) + (Minutes * 60000) + (Hours * 3600000);
_ = new AutoClickerDriver(this.TotalMilliseconds, this.MouseButton, this.ClickType, this.CursorPoint, this.ActivePosition, this.SetPosition, this.Slider, this.ManualEntry);
}
else if (this.Slider)
{
this.TotalMilliseconds = SliderSpeed;
_ = new AutoClickerDriver(this.TotalMilliseconds, this.MouseButton, this.ClickType, this.CursorPoint, this.ActivePosition, this.SetPosition, this.Slider, this.ManualEntry);
}
}
private void StopAutoClicker(object sender, EventArgs e)
{
if (ClickerEnabled)
{
ClickerThread.Abort();
ClickerEnabled = false;
StartButton.BackColor = Color.LightGreen;
StopButton.BackColor = Color.Empty;
ClearButton.BackColor = Color.LightBlue;
StartButton.Enabled = true;
StopButton.Enabled = false;
ClearButton.Enabled = true;
ManualRadio.Enabled = true;
SliderRadio.Enabled = true;
ActivePosRadio.Enabled = true;
SetPosRadio.Enabled = true;
if (ManualRadio.Checked)
{
HoursBox.Enabled = true;
MinutesBox.Enabled = true;
SecondsBox.Enabled = true;
MillisecondsBox.Enabled = true;
ManualRadio.Enabled = true;
SliderRadio.Enabled = true;
ActivePosRadio.Enabled = true;
SetPosRadio.Enabled = true;
MouseButtonBox.Enabled = true;
ClickTypeBox.Enabled = true;
if (SetPosRadio.Checked)
{
XPos.Enabled = true;
YPos.Enabled = true;
}
}
else if (SliderRadio.Checked)
{
SpeedSlider.Enabled = true;
MouseButtonBox.Enabled = true;
ClickTypeBox.Enabled = true;
if (SetPosRadio.Checked)
{
XPos.Enabled = true;
YPos.Enabled = true;
}
}
}
}
//Hotkeys for when the window is in focus
private void HotKeys(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
{
if(ClickerEnabled == true)
{
this.ClickerThread.Abort();
ClickerEnabled = false;
}
Application.Exit();
}
if(e.KeyCode == Keys.F8)
{
ClearButton.PerformClick();
}
}
private void ClearEntryBoxes(object sender, EventArgs e)
{
HoursBox.Text = "";
MinutesBox.Text = "";
SecondsBox.Text = "";
MillisecondsBox.Text = "";
XPos.Text = "";
YPos.Text = "";
this.Milliseconds = 0;
this.Seconds = 0;
this.Minutes = 0;
this.Hours = 0;
this.XPosition = 0;
this.YPosition = 0;
MouseButtonBox.SelectedIndex = 0;
ClickTypeBox.SelectedIndex = 0;
}
private void SetPositionRadioSelector(object sender, EventArgs e)
{
this.SetPosition = true;
this.ActivePosition = false;
XPos.Enabled = true;
YPos.Enabled = true;
}
private void SetActiveRadioSelector(object sender, EventArgs e)
{
this.SetPosition = false;
this.ActivePosition = true;
XPos.Enabled = false;
YPos.Enabled = false;
}
private void SetManualEntryRadioSelector(object sender, EventArgs e)
{
SpeedSlider.Enabled = false;
HoursBox.Enabled = true;
MinutesBox.Enabled = true;
SecondsBox.Enabled = true;
MillisecondsBox.Enabled = true;
this.ManualEntry = true;
this.Slider = false;
this.SliderSpeed = 0;
}
private void SetSliderRadioButton(object sender, EventArgs e)
{
SpeedSlider.Enabled = true;
HoursBox.Enabled = false;
MinutesBox.Enabled = false;
SecondsBox.Enabled = false;
MillisecondsBox.Enabled = false;
this.Slider = true;
this.ManualEntry = false;
this.SliderSpeed = 0;
}
private void SliderScroll(object sender, EventArgs e)
{
this.SliderSpeed = SpeedSlider.Value * 10;
SliderSpeedValue.Text = this.SliderSpeed.ToString();
}
private void NumericValidation(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != '\b'))
{
e.Handled = true;
}
}
}
}