-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQwertyClicker.cs
More file actions
379 lines (347 loc) · 13.7 KB
/
QwertyClicker.cs
File metadata and controls
379 lines (347 loc) · 13.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
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Net;
using System.Reflection;
using Siticone.Desktop.UI.WinForms;
using YamlDotNet.Core.Tokens;
using System.IO.Compression;
using System;
namespace QwertyClicker
{
public partial class QwertyClicker : Form
{
public bool soundClicks = false;
public Discord? RPC;
public QwertyClicker()
{
InitializeComponent();
Logger.info("Initilized all components!");
this.StartDiscordRPC();
}
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
private static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private void moveWindow(object sender, MouseEventArgs ev)
{
if (ev.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, 0xA1, 0x2, 0);
}
}
private void updateCPS(object sender, EventArgs ev)
{
CPSValue.Text = CPSTrackbar.Value + " CPS";
if (CPSTrackbar.Value > 19)
{
ClickSoundsSwitch.Enabled = false;
if (SoundClickVolumeTrackbar.Enabled) SoundClickVolumeTrackbar.Enabled = false;
} else
{
ClickSoundsSwitch.Enabled = true;
if (ClickSoundsSwitch.Checked) SoundClickVolumeTrackbar.Enabled = true;
}
}
private void Exit_Click(object sender, EventArgs e)
{
this.StopDiscordRPC();
Application.Exit();
Logger.notice("Exiting...");
}
private void DiscordLink_Open(object sender, EventArgs ev) => Process.Start("https://discord.gg/9QApUXEvpJ");
private void GithubLink_Open(object sender, EventArgs ev) => Process.Start("https://github.com/QwertyDevelopment");
private void WebsiteLink_Open(object sender, EventArgs ev) => Process.Start("https://qwertydev.tk/");
private void DownloadSoundClicks(object sender, EventArgs ev)
{
if (ClickSoundsSwitch.Checked)
{
if (!File.Exists(Path.GetTempPath() + "\\Clicks.wav"))
{
try
{
var WebClient = new WebClient(); // I know this method is obsolete but its better than HttpClient
WebClient.DownloadFileAsync(new Uri("https://raw.githubusercontent.com/QwertyDevelopment/QwertyClicker/main/Clicks.wav"), Path.GetTempPath() + "\\Clicks.wav");
LoggerLabel.Text = "Downloading: 0%";
WebClient.DownloadProgressChanged += (s, e) =>
{
LoggerLabel.Text = "Downloading: " + e.ProgressPercentage;
Logger.info("Downloading Sound Clicks: " + e.ProgressPercentage);
};
WebClient.DownloadFileCompleted += (s, e) =>
{
LoggerLabel.Text = "Downloaded Sound Clicks!";
Logger.notice("Downloaded Sound Clicks!");
};
}
catch (WebException error)
{
LoggerLabel.Text = "Download Failed.";
Logger.error("Download Failed: " + error.Message);
Logger.error("Unable to download required files...");
ErrorDownloading.Show();
ClickSoundsSwitch.Checked = false;
};
}
else
{
LoggerLabel.Text = "Enabled Sound Clicks!";
this.soundClicks = true;
Logger.notice("Enabled Sound Clicks!");
SoundClickVolumeTrackbar.Enabled = true;
}
} else
{
Logger.notice("Disabled Sound Clicks!");
LoggerLabel.Text = "Disabled Sound Clicks!";
this.soundClicks = false;
SoundClickVolumeTrackbar.Enabled = false;
}
}
private void CheckUpdates()
{
var WebClient = new WebClient { Encoding = System.Text.Encoding.UTF8 };
try
{
if (Version.Parse(WebClient.DownloadString("https://raw.githubusercontent.com/QwertyDevelopment/QwertyClicker/main/version.txt")) > Version.Parse(Assembly.GetEntryAssembly().GetName().Version.ToString()))
{
if (NewUpdateDialog.Show() == DialogResult.Yes)
{
this.UpdateSoftware();
}
}
}
catch
{
Logger.error("Unable to download required files to update!");
ErrorDownloading.Show();
return;
}
}
private void UpdateSoftware()
{
var WebClient = new WebClient();
try
{
WebClient.DownloadDataAsync(new Uri("https://raw.githubusercontent.com/QwertyDevelopment/QwertyClicker/releases/latest/QwertyClicker.zip"), Path.GetTempPath() + "\\QwertyClicker.zip");
WebClient.DownloadProgressChanged += (s, e) =>
{
LoggerLabel.Text = "Downloading: " + e.ProgressPercentage;
Logger.info("Downloading Latest Version: " + e.ProgressPercentage);
};
WebClient.DownloadFileCompleted += (s, e) =>
{
LoggerLabel.Text = "Downloaded Latest Version!";
Logger.notice("Downloaded Latest Version!");
this.RunNewUpdate();
};
} catch (WebException error)
{
LoggerLabel.Text = "Download Failed.";
Logger.error("Download Failed: " + error.Message);
Logger.error("Unable to download required files...");
ErrorDownloading.Show();
}
}
private void RunNewUpdate()
{
try
{
Logger.notice("Initilizing new update..");
File.Move(Path.GetTempPath() + "\\QwertyClicker.zip", Directory.GetCurrentDirectory() + "\\QwertyClicker.zip");
Directory.Delete(Directory.GetCurrentDirectory());
Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\QwertyClicker_New");
ZipFile.ExtractToDirectory(Directory.GetCurrentDirectory() + "\\QwertyClicker.zip", Directory.GetCurrentDirectory() + "\\QwertyClicker_New");
Process.Start(Directory.GetCurrentDirectory() + "\\QwertyzClicker_New\\QwertyClicker.exe");
Logger.notice("Initilized!");
Logger.notice("Exiting...");
Application.Exit();
} catch
{
RunUpdateError.Show();
}
}
private IntPtr hWnd;
private void StartAutoClicker()
{
Logger.notice("Autoclicking Timer has started.");
Timer.Start();
}
public async void AutoClickerTask(object sender, EventArgs ev)
{
if (OnlyMinecraftSwitch.Checked)
{
Process[] processes = Process.GetProcesses();
foreach (Process clsProcess in processes)
{
if (GetForegroundWindow() == clsProcess.MainWindowHandle)
{
this.hWnd = FindWindow(null, clsProcess.ProcessName);
}
}
string? CurrentWindow = this.getActiveWindowName();
if (CurrentWindow == null)
{
return;
}
if (CurrentWindow.Contains("javaw") || CurrentWindow.Contains("minecraft.windows")) // support bedrock and java
{
if (LeftClickCheckbox.Checked)
{
if (MouseButtons == MouseButtons.Left)
{
PostMessage(hWnd, 0x0201, 0, 0);
await Task.Delay(30);
PostMessage(hWnd, 0x0202, 0, 0);
}
}
else if (RightClickCheckbox.Checked)
{
if (MouseButtons == MouseButtons.Right)
{
PostMessage(hWnd, 0x0204, 0, 0);
await Task.Delay(30);
PostMessage(hWnd, 0x0205, 0, 0);
}
}
}
}
else
{
Process[] processes = Process.GetProcesses();
foreach (Process clsProcess in processes)
{
if (GetForegroundWindow() == clsProcess.MainWindowHandle)
{
this.hWnd = FindWindow(null, clsProcess.ProcessName);
}
}
string? currentwindow = this.getActiveWindowName();
if (LeftClickCheckbox.Checked)
{
if (MouseButtons == MouseButtons.Left)
{
PostMessage(hWnd, 0x0201, 0, 0);
await Task.Delay(30);
PostMessage(hWnd, 0x0202, 0, 0);
}
}
else if (RightClickCheckbox.Checked)
{
if (MouseButtons == MouseButtons.Right)
{
PostMessage(hWnd, 0x0204, 0, 0);
await Task.Delay(30);
PostMessage(hWnd, 0x0205, 0, 0);
}
}
}
}
public string ?getActiveWindowName()
{
try
{
var activateHandle = GetForegroundWindow();
Process[] processes = Process.GetProcesses();
foreach (Process clsProcess in processes)
{
if (activateHandle == clsProcess.MainWindowHandle)
{
string processName = clsProcess.ProcessName;
return processName;
}
}
}
catch { }
return null;
}
public void StopAutoClicker()
{
Logger.notice("Autoclicking Timer has stopped.");
Timer.Stop();
}
public void StartDiscordRPC()
{
Logger.info("Starting discord rich presence...");
this.RPC = new Discord("1057226850524479529");
this.RPC.Start();
}
public void StopDiscordRPC()
{
Logger.info("Stopping discord rich presence...");
if(this.RPC != null)
{
this.RPC.Stop();
} else
{
Logger.error("Rich presence is not started yet...");
}
}
private void Minimize_Click(object sender, EventArgs ev) => Logger.notice("Minimizing...");
private void MenuPrompt(object sender, MouseEventArgs ev)
{
if (ev.Button == MouseButtons.Right)
{
Menu.Show(Cursor.Position.X, Cursor.Position.Y);
}
}
private void UpdateButton_Click(object sender, EventArgs e) => this.CheckUpdates();
private void UpdateMenu_Click(object sender, EventArgs e) => this.CheckUpdates();
private void ChangeSoundClicksVolume(object sender, EventArgs e)
{
ClicksVolumeLabel.Text = "Sound Clicks Volume: " + SoundClickVolumeTrackbar.Value + "%";
}
private void RPCSwitch_Toggle(object sender, EventArgs e)
{
if (RPCSwitch.Checked)
{
this.StartDiscordRPC();
LoggerLabel.Text = "Enabled Discord RPC!";
} else
{
this.StopDiscordRPC();
LoggerLabel.Text = "Disabled Discord RPC!";
}
}
private void Toggle_Click(object sender, EventArgs e)
{
if(Toggle.Text == "Enable")
{
Toggle.Text = "Disable";
this.StartAutoClicker();
} else
{
Toggle.Text = "Enable";
this.StopAutoClicker();
}
}
private void LeftClickCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (RightClickCheckbox.Enabled)
{
RightClickCheckbox.Enabled = false;
} else
{
RightClickCheckbox.Enabled = true;
}
}
private void RightClickCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (LeftClickCheckbox.Enabled)
{
LeftClickCheckbox.Enabled = false;
}
else
{
LeftClickCheckbox.Enabled = true;
}
}
}
}