forked from Phaiax/Key-n-Stroke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardRawEvent.cs
584 lines (401 loc) · 13.6 KB
/
KeyboardRawEvent.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
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using KeyNStroke;
namespace KeyNStroke
{
public enum KeyUpDown
{
Undefined,
Up,
Down
}
public class KeyboardRawEventArgs
{
public bool Shift;
public bool LShift;
public bool RShift;
public bool Ctrl;
public bool LCtrl;
public bool RCtrl;
public bool Caps;
public bool LWin;
public bool RWin;
public bool Alt;
public bool LAlt;
public bool RAlt; // Alt Gr
public bool Numlock;
public bool Scrollock;
public int vkCode { get { return Kbdllhookstruct.vkCode; } }
private Key key;
public Key Key { get { return key; } }
public KeyUpDown Method = KeyUpDown.Undefined;
public bool Uppercase { get { return (Shift && !Caps) || (Caps && !Shift); } }
public bool OnlyShiftOrCaps { get { return !Ctrl && !LWin && !RWin && !Alt; } }
public bool NoModifiers { get { return !Ctrl && !LWin && !RWin && !Alt && !Shift; } }
public bool Win { get { return LWin || RWin; } }
public NativeMethodsKeyboard.KBDLLHOOKSTRUCT Kbdllhookstruct;
public byte[] keyState; // 256 bytes
public KeyboardRawEventArgs(NativeMethodsKeyboard.KBDLLHOOKSTRUCT Kbdllhookstruct)
{
this.Kbdllhookstruct = Kbdllhookstruct;
this.key = KeyInterop.KeyFromVirtualKey(this.vkCode); /* cache */
}
}
public delegate void KeyboardRawEventHandler(KeyboardRawEventArgs e);
public interface IKeyboardRawEventProvider : IDisposable
{
event KeyboardRawEventHandler KeyEvent;
}
public enum WindowsVirtualKey
{
[Description("Left mouse button")]
VK_LBUTTON = 0x01,
[Description("Right mouse button")]
VK_RBUTTON = 0x02,
[Description("Control-break processing")]
VK_CANCEL = 0x03,
[Description("Middle mouse button (three-button mouse)")]
VK_MBUTTON = 0x04,
[Description("X1 mouse button")]
VK_XBUTTON1 = 0x05,
[Description("X2 mouse button")]
VK_XBUTTON2 = 0x06,
[Description("BACKSPACE key")]
VK_BACK = 0x08,
[Description("TAB key")]
VK_TAB = 0x09,
[Description("CLEAR key")]
VK_CLEAR = 0x0C,
[Description("ENTER key")]
VK_RETURN = 0x0D,
[Description("SHIFT key")]
VK_SHIFT = 0x10,
[Description("CTRL key")]
VK_CONTROL = 0x11,
[Description("ALT key")]
VK_MENU = 0x12,
[Description("PAUSE key")]
VK_PAUSE = 0x13,
[Description("CAPS LOCK key")]
VK_CAPITAL = 0x14,
[Description("IME Kana mode")]
VK_KANA = 0x15,
[Description("IME Hanguel mode (maintained for compatibility; use VK_HANGUL)")]
VK_HANGUEL = 0x15,
[Description("IME Hangul mode")]
VK_HANGUL = 0x15,
[Description("IME Junja mode")]
VK_JUNJA = 0x17,
[Description("IME final mode")]
VK_FINAL = 0x18,
[Description("IME Hanja mode")]
VK_HANJA = 0x19,
[Description("IME Kanji mode")]
VK_KANJI = 0x19,
[Description("ESC key")]
VK_ESCAPE = 0x1B,
[Description("IME convert")]
VK_CONVERT = 0x1C,
[Description("IME nonconvert")]
VK_NONCONVERT = 0x1D,
[Description("IME accept")]
VK_ACCEPT = 0x1E,
[Description("IME mode change request")]
VK_MODECHANGE = 0x1F,
[Description("SPACEBAR")]
VK_SPACE = 0x20,
[Description("PAGE UP key")]
VK_PRIOR = 0x21,
[Description("PAGE DOWN key")]
VK_NEXT = 0x22,
[Description("END key")]
VK_END = 0x23,
[Description("HOME key")]
VK_HOME = 0x24,
[Description("LEFT ARROW key")]
VK_LEFT = 0x25,
[Description("UP ARROW key")]
VK_UP = 0x26,
[Description("RIGHT ARROW key")]
VK_RIGHT = 0x27,
[Description("DOWN ARROW key")]
VK_DOWN = 0x28,
[Description("SELECT key")]
VK_SELECT = 0x29,
[Description("PRINT key")]
VK_PRINT = 0x2A,
[Description("EXECUTE key")]
VK_EXECUTE = 0x2B,
[Description("PRINT SCREEN key")]
VK_SNAPSHOT = 0x2C,
[Description("INS key")]
VK_INSERT = 0x2D,
[Description("DEL key")]
VK_DELETE = 0x2E,
[Description("HELP key")]
VK_HELP = 0x2F,
[Description("0 key")]
K_0 = 0x30,
[Description("1 key")]
K_1 = 0x31,
[Description("2 key")]
K_2 = 0x32,
[Description("3 key")]
K_3 = 0x33,
[Description("4 key")]
K_4 = 0x34,
[Description("5 key")]
K_5 = 0x35,
[Description("6 key")]
K_6 = 0x36,
[Description("7 key")]
K_7 = 0x37,
[Description("8 key")]
K_8 = 0x38,
[Description("9 key")]
K_9 = 0x39,
[Description("A key")]
K_A = 0x41,
[Description("B key")]
K_B = 0x42,
[Description("C key")]
K_C = 0x43,
[Description("D key")]
K_D = 0x44,
[Description("E key")]
K_E = 0x45,
[Description("F key")]
K_F = 0x46,
[Description("G key")]
K_G = 0x47,
[Description("H key")]
K_H = 0x48,
[Description("I key")]
K_I = 0x49,
[Description("J key")]
K_J = 0x4A,
[Description("K key")]
K_K = 0x4B,
[Description("L key")]
K_L = 0x4C,
[Description("M key")]
K_M = 0x4D,
[Description("N key")]
K_N = 0x4E,
[Description("O key")]
K_O = 0x4F,
[Description("P key")]
K_P = 0x50,
[Description("Q key")]
K_Q = 0x51,
[Description("R key")]
K_R = 0x52,
[Description("S key")]
K_S = 0x53,
[Description("T key")]
K_T = 0x54,
[Description("U key")]
K_U = 0x55,
[Description("V key")]
K_V = 0x56,
[Description("W key")]
K_W = 0x57,
[Description("X key")]
K_X = 0x58,
[Description("Y key")]
K_Y = 0x59,
[Description("Z key")]
K_Z = 0x5A,
[Description("Left Windows key (Natural keyboard)")]
VK_LWIN = 0x5B,
[Description("Right Windows key (Natural keyboard)")]
VK_RWIN = 0x5C,
[Description("Applications key (Natural keyboard)")]
VK_APPS = 0x5D,
[Description("Computer Sleep key")]
VK_SLEEP = 0x5F,
[Description("Numeric keypad 0 key")]
VK_NUMPAD0 = 0x60,
[Description("Numeric keypad 1 key")]
VK_NUMPAD1 = 0x61,
[Description("Numeric keypad 2 key")]
VK_NUMPAD2 = 0x62,
[Description("Numeric keypad 3 key")]
VK_NUMPAD3 = 0x63,
[Description("Numeric keypad 4 key")]
VK_NUMPAD4 = 0x64,
[Description("Numeric keypad 5 key")]
VK_NUMPAD5 = 0x65,
[Description("Numeric keypad 6 key")]
VK_NUMPAD6 = 0x66,
[Description("Numeric keypad 7 key")]
VK_NUMPAD7 = 0x67,
[Description("Numeric keypad 8 key")]
VK_NUMPAD8 = 0x68,
[Description("Numeric keypad 9 key")]
VK_NUMPAD9 = 0x69,
[Description("Multiply key")]
VK_MULTIPLY = 0x6A,
[Description("Add key")]
VK_ADD = 0x6B,
[Description("Separator key")]
VK_SEPARATOR = 0x6C,
[Description("Subtract key")]
VK_SUBTRACT = 0x6D,
[Description("Decimal key")]
VK_DECIMAL = 0x6E,
[Description("Divide key")]
VK_DIVIDE = 0x6F,
[Description("F1 key")]
VK_F1 = 0x70,
[Description("F2 key")]
VK_F2 = 0x71,
[Description("F3 key")]
VK_F3 = 0x72,
[Description("F4 key")]
VK_F4 = 0x73,
[Description("F5 key")]
VK_F5 = 0x74,
[Description("F6 key")]
VK_F6 = 0x75,
[Description("F7 key")]
VK_F7 = 0x76,
[Description("F8 key")]
VK_F8 = 0x77,
[Description("F9 key")]
VK_F9 = 0x78,
[Description("F10 key")]
VK_F10 = 0x79,
[Description("F11 key")]
VK_F11 = 0x7A,
[Description("F12 key")]
VK_F12 = 0x7B,
[Description("F13 key")]
VK_F13 = 0x7C,
[Description("F14 key")]
VK_F14 = 0x7D,
[Description("F15 key")]
VK_F15 = 0x7E,
[Description("F16 key")]
VK_F16 = 0x7F,
[Description("F17 key")]
VK_F17 = 0x80,
[Description("F18 key")]
VK_F18 = 0x81,
[Description("F19 key")]
VK_F19 = 0x82,
[Description("F20 key")]
VK_F20 = 0x83,
[Description("F21 key")]
VK_F21 = 0x84,
[Description("F22 key")]
VK_F22 = 0x85,
[Description("F23 key")]
VK_F23 = 0x86,
[Description("F24 key")]
VK_F24 = 0x87,
[Description("NUM LOCK key")]
VK_NUMLOCK = 0x90,
[Description("SCROLL LOCK key")]
VK_SCROLL = 0x91,
[Description("Left SHIFT key")]
VK_LSHIFT = 0xA0,
[Description("Right SHIFT key")]
VK_RSHIFT = 0xA1,
[Description("Left CONTROL key")]
VK_LCONTROL = 0xA2,
[Description("Right CONTROL key")]
VK_RCONTROL = 0xA3,
[Description("Left MENU key")]
VK_LMENU = 0xA4,
[Description("Right MENU key")]
VK_RMENU = 0xA5,
[Description("Browser Back key")]
VK_BROWSER_BACK = 0xA6,
[Description("Browser Forward key")]
VK_BROWSER_FORWARD = 0xA7,
[Description("Browser Refresh key")]
VK_BROWSER_REFRESH = 0xA8,
[Description("Browser Stop key")]
VK_BROWSER_STOP = 0xA9,
[Description("Browser Search key")]
VK_BROWSER_SEARCH = 0xAA,
[Description("Browser Favorites key")]
VK_BROWSER_FAVORITES = 0xAB,
[Description("Browser Start and Home key")]
VK_BROWSER_HOME = 0xAC,
[Description("Volume Mute key")]
VK_VOLUME_MUTE = 0xAD,
[Description("Volume Down key")]
VK_VOLUME_DOWN = 0xAE,
[Description("Volume Up key")]
VK_VOLUME_UP = 0xAF,
[Description("Next Track key")]
VK_MEDIA_NEXT_TRACK = 0xB0,
[Description("Previous Track key")]
VK_MEDIA_PREV_TRACK = 0xB1,
[Description("Stop Media key")]
VK_MEDIA_STOP = 0xB2,
[Description("Play/Pause Media key")]
VK_MEDIA_PLAY_PAUSE = 0xB3,
[Description("Start Mail key")]
VK_LAUNCH_MAIL = 0xB4,
[Description("Select Media key")]
VK_LAUNCH_MEDIA_SELECT = 0xB5,
[Description("Start Application 1 key")]
VK_LAUNCH_APP1 = 0xB6,
[Description("Start Application 2 key")]
VK_LAUNCH_APP2 = 0xB7,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ';:' key")]
VK_OEM_1 = 0xBA,
[Description("For any country/region, the '+' key")]
VK_OEM_PLUS = 0xBB,
[Description("For any country/region, the ',' key")]
VK_OEM_COMMA = 0xBC,
[Description("For any country/region, the '-' key")]
VK_OEM_MINUS = 0xBD,
[Description("For any country/region, the '.' key")]
VK_OEM_PERIOD = 0xBE,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '/?' key")]
VK_OEM_2 = 0xBF,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '`~' key")]
VK_OEM_3 = 0xC0,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '[{' key")]
VK_OEM_4 = 0xDB,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the '\\|' key")]
VK_OEM_5 = 0xDC,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the ']}' key")]
VK_OEM_6 = 0xDD,
[Description("Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the 'single-quote/double-quote' key")]
VK_OEM_7 = 0xDE,
[Description("Used for miscellaneous characters; it can vary by keyboard.")]
VK_OEM_8 = 0xDF,
[Description("Either the angle bracket key or the backslash key on the RT 102-key keyboard")]
VK_OEM_102 = 0xE2,
[Description("IME PROCESS key")]
VK_PROCESSKEY = 0xE5,
[Description("Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP")]
VK_PACKET = 0xE7,
[Description("Attn key")]
VK_ATTN = 0xF6,
[Description("CrSel key")]
VK_CRSEL = 0xF7,
[Description("ExSel key")]
VK_EXSEL = 0xF8,
[Description("Erase EOF key")]
VK_EREOF = 0xF9,
[Description("Play key")]
VK_PLAY = 0xFA,
[Description("Zoom key")]
VK_ZOOM = 0xFB,
[Description("PA1 key")]
VK_PA1 = 0xFD,
[Description("Clear key")]
VK_OEM_CLEAR = 0xFE,
}
}