0
|
1 // Written in the D programming language
|
|
2 // www.digitalmars.com/d/
|
|
3
|
|
4 /*
|
|
5 * The contents of this file are subject to the Mozilla Public License Version
|
|
6 * 1.1 (the "License"); you may not use this file except in compliance with
|
|
7 * the License. You may obtain a copy of the License at
|
|
8 * http://www.mozilla.org/MPL/
|
|
9 *
|
|
10 * Software distributed under the License is distributed on an "AS IS" basis,
|
|
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
12 * for the specific language governing rights and limitations under the
|
|
13 * License.
|
|
14 *
|
|
15 * The Original Code is the Dynamin library.
|
|
16 *
|
|
17 * The Initial Developer of the Original Code is Jordan Miner.
|
|
18 * Portions created by the Initial Developer are Copyright (C) 2007-2009
|
|
19 * the Initial Developer. All Rights Reserved.
|
|
20 *
|
|
21 * Contributor(s):
|
|
22 * Jordan Miner <jminer7@gmail.com>
|
|
23 *
|
|
24 */
|
|
25
|
|
26 module dynamin.gui.key;
|
|
27
|
|
28 import dynamin.core.string;
|
|
29
|
|
30 /**
|
|
31 * No Menu key is included because Shift+F10 is used instead.
|
|
32 * Note: Windows does not send KeyDown events for PrintScreen, only KeyUp.
|
|
33 */
|
|
34 enum Key {
|
|
35 None,
|
|
36 Escape,
|
|
37 Tab,
|
|
38 Backspace,
|
|
39 Enter,
|
|
40 Space,
|
|
41
|
|
42 Left,
|
|
43 Right,
|
|
44 Up,
|
|
45 Down,
|
|
46
|
|
47 Insert,
|
|
48 Delete,
|
|
49 Home,
|
|
50 End,
|
|
51 PageUp,
|
|
52 PageDown,
|
|
53
|
|
54 PrintScreen,
|
|
55 Pause,
|
|
56
|
|
57 CapsLock,
|
|
58 NumLock,
|
|
59 ScrollLock,
|
|
60
|
|
61 NumPad0,
|
|
62 NumPad1,
|
|
63 NumPad2,
|
|
64 NumPad3,
|
|
65 NumPad4,
|
|
66 NumPad5,
|
|
67 NumPad6,
|
|
68 NumPad7,
|
|
69 NumPad8,
|
|
70 NumPad9,
|
|
71 NumPadDivide,
|
|
72 NumPadMultiply,
|
|
73 NumPadSubtract,
|
|
74 NumPadAdd,
|
|
75 NumPadDecimal, // TODO: NumPadPoint?
|
|
76
|
|
77 Backquote,
|
|
78 Minus,
|
|
79 Equals,
|
|
80 OpenBracket,
|
|
81 CloseBracket,
|
|
82 Backslash,
|
|
83 Semicolon,
|
|
84 Quote,
|
|
85 Comma,
|
|
86 Period,
|
|
87 Slash,
|
|
88
|
|
89 /// Windows sends these messages when the Menu key is pressed and released:
|
|
90 /// Menu pressed, Menu released, Shift pressed, F10 pressed, F10 released, Shift released
|
|
91 /// So if any program responds to either Menu or Shift+F10, it will work right.
|
|
92 Menu, // right of spacebar, between WinKey and Ctrl
|
|
93
|
|
94 // digits
|
|
95 D0 = 0x30, D1, D2, D3, D4, D5, D6, D7, D8, D9 = 0x39,
|
|
96 A = 0x41, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z = 0x5A,
|
|
97 F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
|
|
98
|
|
99 VolumeUp,
|
|
100 VolumeDown,
|
|
101 VolumeMute,
|
|
102
|
|
103 PlayPause,
|
|
104 Stop,
|
|
105 NextTrack,
|
|
106 PrevTrack,
|
|
107
|
|
108 Shift = 0x10000,
|
|
109 Control = 0x20000,
|
|
110 Alt = 0x40000
|
|
111 }
|
|
112
|
|
113 /*string KeyToString(Key key) {
|
|
114 static string[] table = [
|
|
115 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
|
116 "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
|
|
117 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
|
118 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
|
|
119 "Escape", "Tab", "Backspace", "Enter", "Space",
|
|
120 "Left Arrow", "Right Arrow", "Up Arrow", "Down Arrow",
|
|
121 "Insert", "Delete", "Home", "End", "Page Up", "Page Down",
|
|
122 "Print Screen", "Pause",
|
|
123 "Caps Lock", "Num Lock", "Scroll Lock",
|
|
124 "NumPad0", "NumPad1", "NumPad2", "NumPad3", "NumPad4",
|
|
125 "NumPad5", "NumPad6", "NumPad7", "NumPad8", "NumPad9",
|
|
126 "NumPad/", "NumPad*", "NumPad-", "NumPad+", "NumPad.",
|
|
127 "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/",
|
|
128 "Shift", "Ctrl", "Alt"
|
|
129 ];
|
|
130 return table[key];
|
|
131 }
|
|
132 Key toKey(string str) {
|
|
133 foreach(i, s; table)
|
|
134 if(s == str)
|
|
135 return i;
|
|
136 return
|
|
137 }
|
|
138 unittest {
|
|
139 assert(keyToString(Key.D0) == "0");
|
|
140 assert(keyToString(Key.A) == "A");
|
|
141 assert(keyToString(Key.N) == "N");
|
|
142 assert(keyToString(Key.F1) == "F1");
|
|
143 assert(keyToString(Key.Escape) == "Escape");
|
|
144 assert(keyToString(Key.Left) == "Left");
|
|
145 assert(keyToString(Key.Up) == "Up");
|
|
146 assert(keyToString(Key.Insert) == "Insert");
|
|
147 assert(keyToString(Key.PrintScreen) == "Print Screen");
|
|
148 assert(keyToString(Key.Pause) == "Pause");
|
|
149 assert(keyToString(Key.CapsLock) == "CapsLock");
|
|
150 assert(keyToString(Key.NumPad0) == "NumPad0");
|
|
151 assert(keyToString(Key.NumPad5) == "NumPad5");
|
|
152 assert(keyToString(Key.NumPadDivide) == "NumPad/");
|
|
153 assert(keyToString(Key.Backquote) == "`");
|
|
154 assert(keyToString(Key.Control) == "Ctrl");
|
|
155 }*/
|
|
156
|