-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
168 lines (139 loc) · 5.11 KB
/
Form1.cs
File metadata and controls
168 lines (139 loc) · 5.11 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
using System.Runtime.InteropServices;
namespace AutoClickerNetCore
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ThemeManager.ApplyTheme(this, checkBoxDarkMode.Checked);
GlobalHotKey.RegisterGlobalHotKey(Handle);
}
// Import mouse_event from user32.dll
[DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo);
private const uint MOUSEEVENTF_MOVE = 0x0001;
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
private const uint MOUSEEVENTF_LEFTUP = 0x0004;
private static bool HALT_CLICKIES = false;
internal static int DownUpClickPause = 0;
private async void ClickAtPosition(int x, int y)
{
if (checkBoxAlternateClickStrategy.Checked)
{
await SendInputClickStrategy.ClickAt(x, y);
return;
}
// Move the cursor
Cursor.Position = new Point(x, y);
// Simulate mouse click
mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)x, (uint)y, 0, UIntPtr.Zero);
if (DownUpClickPause > 0)
{
await Task.Delay(DownUpClickPause);
}
mouse_event(MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, UIntPtr.Zero);
}
private void ClickDownAtPosition(int x, int y)
{
if (checkBoxAlternateClickStrategy.Checked)
{
SendInputClickStrategy.ClickDownAt(x, y);
return;
}
// Move the cursor
Cursor.Position = new Point(x, y);
// Simulate mouse click
mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)x, (uint)y, 0, UIntPtr.Zero);
}
private void ReleaseClickAtPosition(int x, int y)
{
if (checkBoxAlternateClickStrategy.Checked)
{
SendInputClickStrategy.ClickUpAt(x, y);
return;
}
// Move the cursor
Cursor.Position = new Point(x, y);
// Simulate mouse click
mouse_event(MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, UIntPtr.Zero);
}
private async void buttonXyClick_Click(object sender, EventArgs e)
{
int.TryParse(numericXPos.Text, out int xPos);
int.TryParse(numericYPos.Text, out int yPos);
if (checkBoxClickHold.Checked)
{
ClickDownAtPosition(xPos, yPos);
await Task.Delay((int)numericUpDownClickHoldDuration.Value * 1000);
ReleaseClickAtPosition(xPos, yPos);
}
else
{
for (int i = 0; i <= numericClickCount.Value; i++)
{
if (HALT_CLICKIES)
{
HALT_CLICKIES = false;
return;
}
ClickAtPosition(xPos, yPos);
await Task.Delay((int)numericClickDelay.Value);
}
}
}
private async void buttonClickHold_Click(object sender, EventArgs e)
{
Random random = new Random();
for (int i = 0; i <= numericClickCount.Value; i++)
{
if (HALT_CLICKIES)
{
HALT_CLICKIES = false;
return;
}
int randX = random.Next(1920);
int randY = random.Next(1080);
ClickAtPosition(randX, randY);
await Task.Delay((int)numericClickDelay.Value);
}
}
#region Hotkey Support
// Handle Windows messages
protected override void WndProc(ref Message m)
{
if (m.Msg == GlobalHotKey.WM_HOTKEY)
{
int id = m.WParam.ToInt32();
if (id == 1) // Our registered hotkey ID
{
HALT_CLICKIES = true;
//MessageBox.Show("Global Hotkey (Ctrl + Shift + T) Pressed!", "Hotkey Triggered");
}
}
base.WndProc(ref m);
}
// Unregister hotkey when the form closes
protected override void OnFormClosing(FormClosingEventArgs e)
{
GlobalHotKey.UnegisterGlobalHotKey(Handle);
base.OnFormClosing(e);
}
#endregion
private void checkBoxClickHold_CheckedChanged(object sender, EventArgs e)
{
groupBoxClickies.Enabled = !checkBoxClickHold.Checked;
}
private void numericUpDownPause_ValueChanged(object sender, EventArgs e)
{
if (numericUpDownPause.Value >= 0)
{
DownUpClickPause = (int)numericUpDownPause.Value;
}
}
private void checkBoxDarkMode_CheckedChanged(object sender, EventArgs e)
{
ThemeManager.ApplyTheme(this, checkBoxDarkMode.Checked);
}
}
}