-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hotkey_Configuration.cs
296 lines (256 loc) · 9.33 KB
/
Hotkey_Configuration.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace SightByte
{
partial class Hotkey_Configuration : Form
{
Form1 baseForm;
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
public Hotkey_Configuration(Form1 baseForm)
{
this.baseForm = baseForm;
InitializeComponent();
if(baseForm.preset1Mod != Form1.KeyModifier.None)
textBox1.Text = baseForm.preset1Mod.ToString() + " " + baseForm.keyPreset1.ToString();
else
textBox1.Text = baseForm.keyPreset1.ToString();
if (baseForm.preset2Mod != Form1.KeyModifier.None)
textBox2.Text = baseForm.preset2Mod.ToString() + " " + baseForm.keyPreset2.ToString();
else
textBox2.Text = baseForm.keyPreset2.ToString();
if (baseForm.preset3Mod != Form1.KeyModifier.None)
textBox3.Text = baseForm.preset3Mod.ToString() + " " + baseForm.keyPreset3.ToString();
else
textBox3.Text = baseForm.keyPreset3.ToString();
if (baseForm.preset0Mod != Form1.KeyModifier.None)
textBox4.Text = baseForm.preset0Mod.ToString() + " " + baseForm.keyPreset0.ToString();
else
textBox4.Text = baseForm.keyPreset0.ToString();
}
#region Assembly Attribute Accessors
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
Form1.KeyModifier modifierListener(object sender, KeyEventArgs e)
{
Form1.KeyModifier modifier;
switch (Control.ModifierKeys)
{
case (Keys.Shift):
{
modifier = Form1.KeyModifier.Shift;
break;
}
case (Keys.Alt):
{
modifier = Form1.KeyModifier.Alt;
break;
}
case (Keys.Control):
{
modifier = Form1.KeyModifier.Control;
break;
}
case (Keys.LWin):
{
modifier = Form1.KeyModifier.WinKey;
break;
}
case (Keys.RWin):
{
modifier = Form1.KeyModifier.WinKey;
break;
}
default:
{
modifier = Form1.KeyModifier.None;
break;
}
}
return modifier;
}
private void textBox1_Leave(object sender, EventArgs e)
{
baseForm.editing = false;
}
private void Hotkey_Configuration_Load(object sender, EventArgs e)
{
label1.Focus();
}
private void textBox1_MouseUp(object sender, MouseEventArgs e)
{
baseForm.editing = true;
textBox1.Text = "";
label1.Text = "Enter Hotkey";
}
private void textBox2_MouseUp(object sender, MouseEventArgs e)
{
baseForm.editing = true;
textBox2.Text = "";
label2.Text = "Enter Hotkey";
}
private void textBox3_MouseUp(object sender, MouseEventArgs e)
{
baseForm.editing = true;
textBox3.Text = "";
label3.Text = "Enter Hotkey";
}
private void textBox4_MouseUp(object sender, MouseEventArgs e)
{
baseForm.editing = true;
textBox4.Text = "";
label5.Text = "Enter Hotkey";
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
Form1.KeyModifier modifier = modifierListener(sender, e);
label1.Text = "Preset 1";
if ((int)modifier != 0)
textBox1.Text = modifier.ToString() + " + " + e.KeyCode.ToString();
else
textBox1.Text = e.KeyCode.ToString();
if (textBox1.Text.Count() == 0)
textBox1.Text = "Invalid Key";
baseForm.changeHotKey(1, e, modifier);
label1.Focus();
}
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
Form1.KeyModifier modifier = modifierListener(sender, e);
label2.Text = "Preset 2";
if ((int)modifier != 0)
textBox2.Text = modifier.ToString() + " + " + e.KeyCode.ToString();
else
textBox2.Text = e.KeyCode.ToString();
if (textBox2.Text.Count() == 0)
textBox2.Text = "Invalid Key";
baseForm.changeHotKey(2, e, modifier);
label2.Focus();
}
private void textBox3_KeyUp(object sender, KeyEventArgs e)
{
Form1.KeyModifier modifier = modifierListener(sender, e);
label3.Text = "Preset 3";
if ((int)modifier != 0)
textBox3.Text = modifier.ToString() + " + " + e.KeyCode.ToString();
else
textBox3.Text = e.KeyCode.ToString();
if (textBox3.Text.Count() == 0)
textBox3.Text = "Invalid Key";
baseForm.changeHotKey(3, e, modifier);
label3.Focus();
}
private void textBox4_KeyUp(object sender, KeyEventArgs e)
{
Form1.KeyModifier modifier = modifierListener(sender, e);
label5.Text = "Revert";
if ((int)modifier != 0)
textBox4.Text = modifier.ToString() + " + " + e.KeyCode.ToString();
else
textBox4.Text = e.KeyCode.ToString();
if (textBox4.Text.Count() == 0)
textBox4.Text = "Invalid Key";
baseForm.changeHotKey(0, e, modifier);
label5.Focus();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
private void Hotkey_Configuration_FormClosing(object sender, FormClosingEventArgs e)
{
baseForm.editing = false;
}
}
}