-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoMouse.cs
More file actions
256 lines (237 loc) · 8.95 KB
/
AutoMouse.cs
File metadata and controls
256 lines (237 loc) · 8.95 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
using System;
using System.ComponentModel;
using System.Windows.Forms;
using AutoMouseMover.WinHelper;
using AutoMouseMover.WinWrapper;
using Microsoft.Win32;
namespace XShort
{
public partial class AutoMouse : Form
{
private bool exit = false;
private int sign = 1;
private enum TrayAction : int
{
NOTHING = 0,
AUTO_MOUSE = 1,
AUTO_KEY = 2,
OPEN_ANTI_IDOL = 3
}
public AutoMouse()
{
InitializeComponent();
comboBoxKeys.DataSource = Enum.GetValues(typeof(SendInputWrapper.VirtualKeyShort));
comboBoxLeftClickTray.DataSource = Enum.GetValues(typeof(TrayAction));
comboBoxMidClickTray.DataSource = Enum.GetValues(typeof(TrayAction));
comboBoxRighClickTray.DataSource = Enum.GetValues(typeof(TrayAction));
using (RegistryKey r = Registry.CurrentUser.OpenSubKey("SOFTWARE\\ClearAll\\XShort\\AMI", true))
{
if (r != null)
{
if (r.GetValue("AMI") != null)
numericUpDownIntervalMouse.Value = (int)r.GetValue("AMI");
if (r.GetValue("AMIK") != null)
numericUpDownIntervalKey.Value = (int)r.GetValue("AMIK");
if (r.GetValue("AMIO") != null)
numericUpDownOffset.Value = (int)r.GetValue("AMIO");
if (r.GetValue("AMITray") != null)
checkBoxTrayIcon.Checked = true;
if (r.GetValue("AMIKey") != null)
{
string key = r.GetValue("AMIKey").ToString();
Enum.TryParse<SendInputWrapper.VirtualKeyShort>(key, out SendInputWrapper.VirtualKeyShort vk);
comboBoxKeys.SelectedItem = vk;
}
if (r.GetValue("AMITrayLA") != null)
{
comboBoxLeftClickTray.SelectedIndex = (int)r.GetValue("AMITrayLA");
}
if (r.GetValue("AMITrayMA") != null)
{
comboBoxMidClickTray.SelectedIndex = (int)r.GetValue("AMITrayMA");
}
if (r.GetValue("AMITrayRA") != null)
{
comboBoxRighClickTray.SelectedIndex = (int)r.GetValue("AMITrayRA");
}
}
else
Registry.CurrentUser.CreateSubKey("SOFTWARE\\ClearAll\\XShort\\AMI");
}
}
private void MoveCursor(int offset)
{
// If mouse is outside screen, move it to the center
// In case of multiple screens are used, the mouse will be moved to the center of the main screen
// This has never been a problem to me, but you can modify the code to support multiple screens
if (!CursorHelper.CheckRelativePosition(offset, offset))
{
var res_info = DesktopHelper.GetResolution();
var center_screen_pos = new CursorPosition(res_info.Width / 2, res_info.Height / 2);
CursorHelper.SetPositionAbsolute(center_screen_pos);
}
else
{
CursorHelper.SetPositionRelative(offset, offset);
}
}
private void SendKey(string k)
{
Enum.TryParse<SendInputWrapper.ScanCodeShort>(k, out SendInputWrapper.ScanCodeShort key);
CursorHelper.SendKey(key);
}
public void CloseForm()
{
exit = true;
timerAutoCursor.Stop();
this.Close();
}
private void AutoMouse_FormClosing(object sender, FormClosingEventArgs e)
{
using (RegistryKey r = Registry.CurrentUser.OpenSubKey("SOFTWARE\\ClearAll\\XShort\\AMI", true))
{
r.SetValue("AMI", (int)numericUpDownIntervalMouse.Value);
r.SetValue("AMIK", (int)numericUpDownIntervalKey.Value);
r.SetValue("AMIO", (int)numericUpDownOffset.Value);
if (checkBoxTrayIcon.Checked)
r.SetValue("AMITray", true);
else
r.DeleteValue("AMITray", false);
r.SetValue("AMITrayLA", comboBoxLeftClickTray.SelectedIndex);
r.SetValue("AMITrayMA", comboBoxMidClickTray.SelectedIndex);
r.SetValue("AMITrayRA", comboBoxRighClickTray.SelectedIndex);
r.SetValue("AMIKey", comboBoxKeys.SelectedValue.ToString());
}
if (!exit)
{
e.Cancel = true;
this.Hide();
}
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
NotifyIconClick(comboBoxLeftClickTray.SelectedIndex);
}
else if (e.Button == MouseButtons.Right)
{
NotifyIconClick(comboBoxRighClickTray.SelectedIndex);
}
else
{
NotifyIconClick(comboBoxMidClickTray.SelectedIndex);
}
}
private void NotifyIconClick(int index)
{
if (index == 1)
{
if (checkBoxMoveMouseService.Checked)
{
checkBoxMoveMouseService.Checked = false;
}
else
{
checkBoxMoveMouseService.Checked = true;
}
}
else if (index == 2)
{
if (checkBoxSendKeyService.Checked)
{
checkBoxSendKeyService.Checked = false;
}
else
{
checkBoxSendKeyService.Checked = true;
}
}
else if (index == 3)
{
this.Show();
}
}
private void timerAutoCursor_Tick(object sender, EventArgs e)
{
MoveCursor(sign * (int)numericUpDownOffset.Value);
sign = -sign;
}
private void checkBoxService_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxMoveMouseService.Checked)
{
timerAutoCursor.Interval = 1000 * (int)numericUpDownIntervalMouse.Value;
timerAutoCursor.Start();
numericUpDownIntervalMouse.Enabled = false;
}
else
{
timerAutoCursor.Stop();
numericUpDownIntervalMouse.Enabled = true;
}
UpdateStatus();
}
private void checkBoxTrayIcon_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxTrayIcon.Checked)
{
notifyIconTray.Visible = false;
comboBoxLeftClickTray.Enabled = false;
comboBoxMidClickTray.Enabled = false;
comboBoxRighClickTray.Enabled = false;
}
else
{
notifyIconTray.Visible = true;
comboBoxLeftClickTray.Enabled = true;
comboBoxMidClickTray.Enabled = true;
comboBoxRighClickTray.Enabled = true;
}
}
private void checkBoxSendKey_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxSendKeyService.Checked)
{
timerAutoKey.Interval = 1000 * (int)numericUpDownIntervalKey.Value;
timerAutoKey.Start();
numericUpDownIntervalKey.Enabled = false;
}
else
{
timerAutoKey.Stop();
numericUpDownIntervalKey.Enabled = true;
}
UpdateStatus();
}
private void timerAutoKey_Tick(object sender, EventArgs e)
{
SendKey(comboBoxKeys.SelectedValue.ToString());
}
private void UpdateStatus()
{
bool am = checkBoxMoveMouseService.Checked;
bool ak = checkBoxSendKeyService.Checked;
if (am && ak)
{
notifyIconTray.Icon = Properties.Resources.all_running;
notifyIconTray.Text = "Anti Idol - All services are running";
}
else if (am && !ak)
{
notifyIconTray.Icon = Properties.Resources.mouse_only;
notifyIconTray.Text = "Anti Idol - Auto Mouse service is running";
}
else if (!am && ak)
{
notifyIconTray.Icon = Properties.Resources.keyboard_only;
notifyIconTray.Text = "Anti Idol - Auto Key service running";
}
else
{
notifyIconTray.Icon = Properties.Resources.all_ready;
notifyIconTray.Text = "Idol/Idle";
}
}
}
}