1 /// Key enumeration module.
2 module gfx.window.keys;
3 
4 
5 /// Modifier mask
6 enum KeyMods
7 {
8     none    = 0,
9 
10     ctrlMask        = 0x01,
11     shiftMask       = 0x02,
12     superMask       = 0x04,
13     altMask         = 0x08,
14 
15     leftMask        = 0x20,
16     rightMask       = 0x40,
17 
18     leftCtrl    = ctrlMask  | leftMask,
19     rightCtrl   = ctrlMask  | rightMask,
20     leftShift   = shiftMask | leftMask,
21     rightShift  = shiftMask | rightMask,
22     leftAlt     = altMask   | leftMask,
23     rightAlt    = altMask   | rightMask,
24     leftSuper   = superMask | leftMask,
25     rightSuper  = superMask | rightMask,
26 
27     ctrl        = leftCtrl  | rightCtrl,
28     alt         = leftAlt   | rightAlt,
29     super_      = leftSuper | rightSuper,
30     shift       = leftShift | rightShift,
31 }
32 
33 
34 /// Represents a physical key (or scancode), using QWERTY US keymap as basis.
35 /// I.e. the key "A" on an AZERTY keyboard is represented by `Code.Q`.
36 /// This enum has 256 values and is a perfect candidate for index based
37 /// look-up table.
38 /// Values of enumerants are from the USB HID scancodes table.
39 enum KeyCode : ubyte
40 {
41     none                = 0,
42     errorRollOver       = 1,
43     postFail            = 2,
44     errorUndefined      = 3,
45     a                   = 4,
46     b                   = 5,
47     c                   = 6,
48     d                   = 7,
49     e                   = 8,
50     f                   = 9,
51     g                   = 10,
52     h                   = 11,
53     i                   = 12,
54     j                   = 13,
55     k                   = 14,
56     l                   = 15,
57     m                   = 16,
58     n                   = 17,
59     o                   = 18,
60     p                   = 19,
61     q                   = 20,
62     r                   = 21,
63     s                   = 22,
64     t                   = 23,
65     u                   = 24,
66     v                   = 25,
67     w                   = 26,
68     x                   = 27,
69     y                   = 28,
70     z                   = 29,
71     d1                  = 30,
72     d2                  = 31,
73     d3                  = 32,
74     d4                  = 33,
75     d5                  = 34,
76     d6                  = 35,
77     d7                  = 36,
78     d8                  = 37,
79     d9                  = 38,
80     d0                  = 39,
81     enter               = 40,
82     escape              = 41,
83     backspace           = 42,
84     tab                 = 43,
85     space               = 44,
86     minus               = 45,
87     equals              = 46,
88     leftBracket         = 47,
89     rightBracket        = 48,
90     backslash           = 49,
91     uK_Hash             = 50,
92     semicolon           = 51,
93     quote               = 52,
94     grave               = 53,
95     comma               = 54,
96     period              = 55,
97     slash               = 56,
98     capsLock            = 57,
99     f1                  = 58,
100     f2                  = 59,
101     f3                  = 60,
102     f4                  = 61,
103     f5                  = 62,
104     f6                  = 63,
105     f7                  = 64,
106     f8                  = 65,
107     f9                  = 66,
108     f10                 = 67,
109     f11                 = 68,
110     f12                 = 69,
111     printScreen         = 70,
112     scrollLock          = 71,
113     pause               = 72,
114     insert              = 73,
115     home                = 74,
116     pageUp              = 75,
117     delete_             = 76,
118     end                 = 77,
119     pageDown            = 78,
120     right               = 79,
121     left                = 80,
122     down                = 81,
123     up                  = 82,
124     kp_NumLock          = 83,
125     kp_Divide           = 84,
126     kp_Multiply         = 85,
127     kp_Subtract         = 86,
128     kp_Add              = 87,
129     kp_Enter            = 88,
130     kp_1                = 89,
131     kp_2                = 90,
132     kp_3                = 91,
133     kp_4                = 92,
134     kp_5                = 93,
135     kp_6                = 94,
136     kp_7                = 95,
137     kp_8                = 96,
138     kp_9                = 97,
139     kp_0                = 98,
140     kp_Period           = 99,
141     uK_Backslash        = 100,
142     kp_Equal            = 103,
143     f13                 = 104,
144     f14                 = 105,
145     f15                 = 106,
146     f16                 = 107,
147     f17                 = 108,
148     f18                 = 109,
149     f19                 = 110,
150     f20                 = 111,
151     f21                 = 112,
152     f22                 = 113,
153     f23                 = 114,
154     f24                 = 115,
155     execute             = 116,
156     help                = 117,
157     menu                = 118,
158     select              = 119,
159     stop                = 120,
160     again               = 121,
161     undo                = 122,
162     cut                 = 123,
163     copy                = 124,
164     paste               = 125,
165     find                = 126,
166     mute                = 127,
167     volumeUp            = 128,
168     volumeDown          = 129,
169     lockingCapsLock     = 130,
170     lockingNumLock      = 131,
171     lockingScrollLock   = 132,
172     kp_Comma            = 133,
173     kp_EqualSign        = 134,
174     international1      = 135,
175     international2      = 136,
176     international3      = 137,
177     international4      = 138,
178     international5      = 139,
179     international6      = 140,
180     international7      = 141,
181     international8      = 142,
182     international9      = 143,
183     lang1               = 144,  // Hangul / English toggle
184     lang2               = 145,  // Hanja conversion
185     lang3               = 146,  // Katakana
186     lang4               = 147,  // Hiragana
187     lang5               = 148,  // Zenkaku/Hankaku
188     lang6               = 149,
189     lang7               = 150,
190     lang8               = 151,
191     lang9               = 152,
192     altErase            = 153,
193     sysReq              = 154,
194     cancel              = 155,
195     clear               = 156,
196     prior               = 157,
197     return_             = 158,
198     separator           = 159,
199     out_                = 160,
200     oper                = 161,
201     clearAgain          = 162,
202     crSelProps          = 163,
203     exSel               = 164,
204 
205     kp_00               = 176,
206     kp_000              = 177,
207     thousandsSep        = 178,
208     decimalSep          = 179,
209     currencyUnit        = 180,
210     currencySubUnit     = 181,
211     kp_LeftParent       = 182,
212     kp_RightParent      = 183,
213     kp_LeftCurly        = 184,
214     kp_RightCurly       = 185,
215     kp_Tab              = 186,
216     kp_Backspace        = 187,
217     kp_A                = 188,
218     kp_B                = 189,
219     kp_C                = 190,
220     kp_D                = 191,
221     kp_E                = 192,
222     kp_F                = 193,
223     kp_XOR              = 194,
224     kp_Pow              = 195,
225     kp_Percent          = 196,
226     kp_LeftAngle        = 197,
227     kp_RightAngle       = 198,
228     kp_BitAnd           = 199,
229     kp_LogicAnd         = 200,
230     kp_BitOr            = 201,
231     kp_LogicOr          = 202,
232     kp_Colon            = 203,
233     kp_Hash             = 204,
234     kp_Space            = 205,
235     kp_At               = 206,
236     kp_Not              = 207,
237     kp_MemStore         = 208,
238     kp_MemRecall        = 209,
239     kp_MemClear         = 210,
240     kp_MemAdd           = 211,
241     kp_MemSubtract      = 212,
242     kp_MemMultiply      = 213,
243     kp_MemDivide        = 214,
244     kp_PlusMinus        = 215,
245     kp_Clear            = 216,
246     kp_ClearEntry       = 217,
247     kp_Binary           = 218,
248     kp_Octal            = 219,
249     kp_Decimal          = 220,
250     kp_Hexadecimal      = 221,
251 
252     leftCtrl            = 224,
253     leftShift           = 225,
254     leftAlt             = 226,
255     leftSuper           = 227,
256     rightCtrl           = 228,
257     rightShift          = 229,
258     rightAlt            = 230,
259     rightSuper          = 231,
260 
261     unknown             = 255
262 }
263 
264 /// Represent a virtual key, which is a key translated with a keymap.
265 enum KeySym : uint
266 {
267     none                    = 0,
268 
269     controlMask             = 0x8000_0000,
270     keypadMask              = 0x4000_0000,
271     mediaMask               = 0x2000_0000,
272     imeMask                 = 0x1000_0000,
273 
274     modMask                 = 0x0080_0000,
275 
276     ctrlMask                = 0x0001_0000,
277     shiftMask               = 0x0002_0000,
278     metaMask                = 0x0004_0000,
279     altMask                 = 0x0008_0000,
280     superMask               = 0x0010_0000,
281     leftMask                = 0x0020_0000,
282     rightMask               = 0x0040_0000,
283 
284     latin1SmallMask         = 0x0000_0020,
285 
286     unknown                 = 0x0000_ffdf,
287 
288 
289     escape                  = controlMask | 1,
290     tab,
291     leftTab,
292     backspace,
293     return_,
294     delete_,
295     sysRq,
296     pause,
297     clear,
298 
299     capsLock,
300     numLock,
301     scrollLock,
302 
303     left,
304     up,
305     right,
306     down,
307     pageUp,
308     pageDown,
309     home,
310     end,
311 
312     print,
313     insert,
314     menu,
315     help,
316     break_,
317 
318     f1,
319     f2,
320     f3,
321     f4,
322     f5,
323     f6,
324     f7,
325     f8,
326     f9,
327     f10,
328     f11,
329     f12,
330     f13,
331     f14,
332     f15,
333     f16,
334     f17,
335     f18,
336     f19,
337     f20,
338     f21,
339     f22,
340     f23,
341     f24,
342 
343     kp_Enter                = keypadMask | 1,
344     kp_Delete,
345     kp_Home,
346     kp_Begin,
347     kp_End,
348     kp_PageUp,
349     kp_PageDown,
350     kp_Up,
351     kp_Down,
352     kp_Left,
353     kp_Right,
354     kp_Equal,
355     kp_Multiply,
356     kp_Add,
357     kp_Divide,
358     kp_Subtract,
359     kp_Decimal,
360     kp_Separator,
361 
362     kp_0,
363     kp_1,
364     kp_2,
365     kp_3,
366     kp_4,
367     kp_5,
368     kp_6,
369     kp_7,
370     kp_8,
371     kp_9,
372 
373     leftCtrl                = ctrlMask  | leftMask  | modMask,
374     rightCtrl               = ctrlMask  | rightMask | modMask,
375     leftShift               = shiftMask | leftMask  | modMask,
376     rightShift              = shiftMask | rightMask | modMask,
377     leftAlt                 = altMask   | leftMask  | modMask,
378     rightAlt                = altMask   | rightMask | modMask,
379     leftSuper               = superMask | leftMask  | modMask,
380     rightSuper              = superMask | rightMask | modMask,
381 
382     ctrl                    = leftCtrl  | rightCtrl,
383     shift                   = leftShift | rightShift,
384     alt                     = leftAlt   | rightAlt,
385     super_                  = leftSuper | rightSuper,
386 
387     altGr                   = rightAlt,
388 
389     /*
390      * Latin 1
391      * (ISO/IEC 8859-1 = Unicode U+0020..U+00FF)
392      * Byte 3 = 0
393      */
394     space                   = 0x0000_0020,  /* U+0020 SPACE */
395     exclam                  = 0x0000_0021,  /* U+0021 EXCLAMATION MARK */
396     quoteDbl                = 0x0000_0022,  /* U+0022 QUOTATION MARK */
397     numbersign              = 0x0000_0023,  /* U+0023 NUMBER SIGN */
398     dollar                  = 0x0000_0024,  /* U+0024 DOLLAR SIGN */
399     percent                 = 0x0000_0025,  /* U+0025 PERCENT SIGN */
400     ampersand               = 0x0000_0026,  /* U+0026 AMPERSAND */
401     apostrophe              = 0x0000_0027,  /* U+0027 APOSTROPHE */
402     parenleft               = 0x0000_0028,  /* U+0028 LEFT PARENTHESIS */
403     parenright              = 0x0000_0029,  /* U+0029 RIGHT PARENTHESIS */
404     asterisk                = 0x0000_002a,  /* U+002A ASTERISK */
405     plus                    = 0x0000_002b,  /* U+002B PLUS SIGN */
406     comma                   = 0x0000_002c,  /* U+002C COMMA */
407     minus                   = 0x0000_002d,  /* U+002D HYPHEN-MINUS */
408     period                  = 0x0000_002e,  /* U+002E FULL STOP */
409     slash                   = 0x0000_002f,  /* U+002F SOLIDUS */
410     d0                      = 0x0000_0030,  /* U+0030 DIGIT ZERO */
411     d1                      = 0x0000_0031,  /* U+0031 DIGIT ONE */
412     d2                      = 0x0000_0032,  /* U+0032 DIGIT TWO */
413     d3                      = 0x0000_0033,  /* U+0033 DIGIT THREE */
414     d4                      = 0x0000_0034,  /* U+0034 DIGIT FOUR */
415     d5                      = 0x0000_0035,  /* U+0035 DIGIT FIVE */
416     d6                      = 0x0000_0036,  /* U+0036 DIGIT SIX */
417     d7                      = 0x0000_0037,  /* U+0037 DIGIT SEVEN */
418     d8                      = 0x0000_0038,  /* U+0038 DIGIT EIGHT */
419     d9                      = 0x0000_0039,  /* U+0039 DIGIT NINE */
420     colon                   = 0x0000_003a,  /* U+003A COLON */
421     semicolon               = 0x0000_003b,  /* U+003B SEMICOLON */
422     less                    = 0x0000_003c,  /* U+003C LESS-THAN SIGN */
423     equal                   = 0x0000_003d,  /* U+003D EQUALS SIGN */
424     greater                 = 0x0000_003e,  /* U+003E GREATER-THAN SIGN */
425     question                = 0x0000_003f,  /* U+003F QUESTION MARK */
426     at                      = 0x0000_0040,  /* U+0040 COMMERCIAL AT */
427     a                       = 0x0000_0041,  /* U+0041 LATIN CAPITAL LETTER A */
428     b                       = 0x0000_0042,  /* U+0042 LATIN CAPITAL LETTER B */
429     c                       = 0x0000_0043,  /* U+0043 LATIN CAPITAL LETTER C */
430     d                       = 0x0000_0044,  /* U+0044 LATIN CAPITAL LETTER D */
431     e                       = 0x0000_0045,  /* U+0045 LATIN CAPITAL LETTER E */
432     f                       = 0x0000_0046,  /* U+0046 LATIN CAPITAL LETTER F */
433     g                       = 0x0000_0047,  /* U+0047 LATIN CAPITAL LETTER G */
434     h                       = 0x0000_0048,  /* U+0048 LATIN CAPITAL LETTER H */
435     i                       = 0x0000_0049,  /* U+0049 LATIN CAPITAL LETTER I */
436     j                       = 0x0000_004a,  /* U+004A LATIN CAPITAL LETTER J */
437     k                       = 0x0000_004b,  /* U+004B LATIN CAPITAL LETTER K */
438     l                       = 0x0000_004c,  /* U+004C LATIN CAPITAL LETTER L */
439     m                       = 0x0000_004d,  /* U+004D LATIN CAPITAL LETTER M */
440     n                       = 0x0000_004e,  /* U+004E LATIN CAPITAL LETTER N */
441     o                       = 0x0000_004f,  /* U+004F LATIN CAPITAL LETTER O */
442     p                       = 0x0000_0050,  /* U+0050 LATIN CAPITAL LETTER P */
443     q                       = 0x0000_0051,  /* U+0051 LATIN CAPITAL LETTER Q */
444     r                       = 0x0000_0052,  /* U+0052 LATIN CAPITAL LETTER R */
445     s                       = 0x0000_0053,  /* U+0053 LATIN CAPITAL LETTER S */
446     t                       = 0x0000_0054,  /* U+0054 LATIN CAPITAL LETTER T */
447     u                       = 0x0000_0055,  /* U+0055 LATIN CAPITAL LETTER U */
448     v                       = 0x0000_0056,  /* U+0056 LATIN CAPITAL LETTER V */
449     w                       = 0x0000_0057,  /* U+0057 LATIN CAPITAL LETTER W */
450     x                       = 0x0000_0058,  /* U+0058 LATIN CAPITAL LETTER X */
451     y                       = 0x0000_0059,  /* U+0059 LATIN CAPITAL LETTER Y */
452     z                       = 0x0000_005a,  /* U+005A LATIN CAPITAL LETTER Z */
453     bracketLeft             = 0x0000_005b,  /* U+005B LEFT SQUARE BRACKET */
454     backslash               = 0x0000_005c,  /* U+005C REVERSE SOLIDUS */
455     bracketRight            = 0x0000_005d,  /* U+005D RIGHT SQUARE BRACKET */
456     asciicircum             = 0x0000_005e,  /* U+005E CIRCUMFLEX ACCENT */
457     underscore              = 0x0000_005f,  /* U+005F LOW LINE */
458     grave                   = 0x0000_0060,  /* U+0060 GRAVE ACCENT */
459     braceLeft               = 0x0000_007b,  /* U+007B LEFT CURLY BRACKET */
460     bar                     = 0x0000_007c,  /* U+007C VERTICAL LINE */
461     braceRight              = 0x0000_007d,  /* U+007D RIGHT CURLY BRACKET */
462     asciiTilde              = 0x0000_007e,  /* U+007E TILDE */
463 
464     browserBack             = mediaMask | 1,
465     browserForward,
466     browserStop,
467     browserRefresh,
468     browserHome,
469     browserFavorites,
470     browserSearch,
471     volumeDown,
472     volumeMute,
473     volumeUp,
474     bassBoost,
475     bassUp,
476     bassDown,
477     trebleUp,
478     trebleDown,
479     mediaPlay,
480     mediaStop,
481     mediaPrevious,
482     mediaNext,
483     mediaRecord,
484     mediaPause,
485     mediaTogglePlayPause,
486     standby,
487     openUrl,
488     myComputer,
489     launchMail,
490     launchMedia,
491     launch0,
492     launch1,
493     launch2,
494     launch3,
495     launch4,
496     launch5,
497     launch6,
498     launch7,
499     launch8,
500     launch9,
501     launchA,
502     launchB,
503     launchC,
504     launchD,
505     launchE,
506     launchF,
507     monBrightnessUp,
508     monBrightnessDown,
509     keyboardLightOnOff,
510     keyboardBrightnessUp,
511     keyboardBrightnessDown,
512     powerOff,
513     wakeUp,
514     eject,
515     screenSaver,
516     www,
517     memo,
518     lightBulb,
519     shop,
520     history,
521     addFavorite,
522     hotLinks,
523     brightnessAdjust,
524     finance,
525     community,
526     audioRewind, // Media rewind
527     backForward,
528     applicationLeft,
529     applicationRight,
530     book,
531     cd,
532     calculator,
533     todoList,
534     clearGrab,
535     close,
536     copy,
537     cut,
538     display, // Output switch key
539     dos,
540     documents,
541     excel,
542     explorer,
543     game,
544     go,
545     iTouch,
546     logOff,
547     market,
548     meeting,
549     menuKB,
550     menuPB,
551     mySites,
552     news,
553     officeHome,
554     option,
555     paste,
556     phone,
557     calendar,
558     reply,
559     reload,
560     rotateWindows,
561     rotationPB,
562     rotationKB,
563     save,
564     send,
565     spell,
566     splitScreen,
567     support,
568     taskPane,
569     terminal,
570     tools,
571     travel,
572     video,
573     word,
574     xfer,
575     zoomIn,
576     zoomOut,
577     away,
578     messenger,
579     webCam,
580     mailForward,
581     pictures,
582     music,
583     battery,
584     bluetooth,
585     wlan,
586     uwb,
587     audioForward, // Media fast-forward
588     audioRepeat, // Toggle repeat mode
589     audioRandomPlay, // Toggle shuffle mode
590     subtitle,
591     audioCycleTrack,
592     time,
593     hibernate,
594     view,
595     topMenu,
596     powerDown,
597     suspend,
598     contrastAdjust,
599 
600     launchG,
601     launchH,
602 
603     touchpadToggle,
604     touchpadOn,
605     touchpadOff,
606 
607     micMute,
608 
609     red,
610     green,
611     yellow,
612     blue,
613 
614     channelUp,
615     channelDown,
616 
617     guide,
618     info,
619     settings,
620 
621     micVolumeUp,
622     micVolumeDown,
623 
624     new_,
625     open,
626     find,
627     undo,
628     redo,
629 
630     mediaLast,
631 
632     // Keypad navigation keys
633     select,
634     yes,
635     no,
636 
637     // Newer misc keys
638     cancel,
639     printer,
640     execute,
641     sleep,
642     play, // Not the same as MediaPlay
643     zoom,
644     exit,
645 
646     // Device keys
647     context1,
648     context2,
649     context3,
650     context4,
651     call,      // set absolute state to in a call (do not toggle state)
652     hangUp,    // set absolute state to hang up (do not toggle state)
653     flip,
654     toggleCallHangUp, // a toggle key for answering, or hanging up, based on current call state
655     voiceDial,
656     lastNumberRedial,
657 
658     camera,
659     cameraFocus,
660 
661     convert                         = imeMask | 1,
662     nonConvert,
663     accept,
664     modeSwitch,
665     final_,
666     kana,
667     hangul,
668     junja,
669     hanja,
670     kanji,
671     jisho,
672     masshou,
673     touroku,
674     oyayubiLeft,
675     oyayubiRight,
676 }