1 module iota.controls.keybscancodes;
2 
3 /**
4  * (Mostly) USB HID compatible keyboard scancodes.
5  */
6 public enum ScanCode : uint {
7 	init,
8 	A				=	4,
9 	B				=	5,
10 	C				=	6,
11 	D				=	7,
12 	E				=	8,
13 	F				=	9,
14 	G				=	10,
15 	H				=	11,
16 	I				=	12,
17 	J				=	13,
18 	K				=	14,
19 	L				=	15,
20 	M				=	16,
21 	N				=	17,
22 	O				=	18,
23 	P				=	19,
24 	Q				=	20,
25 	R				=	21,
26 	S				=	22,
27 	T				=	23,
28 	U				=	24,
29 	V				=	25,
30 	W				=	26,
31 	X				=	27,
32 	Y				=	28,
33 	Z				=	29,
34 
35 	n1				=	30,
36 	n2				=	31,
37 	n3				=	32,
38 	n4				=	33,
39 	n5				=	34,
40 	n6				=	35,
41 	n7				=	36,
42 	n8				=	37,
43 	n9				=	38,
44 	n0				=	39,
45 
46 	ENTER			=	40,
47 	ESCAPE			=	41,
48 	BACKSPACE		=	42,
49 	TAB				=	43,
50 	SPACE			=	44,
51 
52 	MINUS			=	45,
53 	EQUALS			=	46,
54 	LEFTBRACKET		=	47,
55 	RIGHTBRACKET	=	48,
56 	BACKSLASH		=	49,
57 	NONUSHASH		=	50,
58 	SEMICOLON		=	51,
59 	APOSTROPHE		=	52,
60 	GRAVE			=	53,
61 	COMMA			=	54,
62 	PERIOD			=	55,
63 	SLASH			=	56,
64 	CAPSLOCK		=	57,
65 
66 	F1				=	58,
67 	F2				=	59,
68 	F3				=	60,
69 	F4				=	61,
70 	F5				=	62,
71 	F6				=	63,
72 	F7				=	64,
73 	F8				=	65,
74 	F9				=	66,
75 	F10				=	67,
76 	F11				=	68,
77 	F12				=	69,
78 
79 	PRINTSCREEN		=	70,
80 	SCROLLLOCK		=	71,
81 	PAUSE			=	72,
82 	INSERT			=	73,
83 	HOME			=	74,
84 	PAGEUP			=	75,
85 	DELETE			=	76,
86 	END				=	77,
87 	PAGEDOWN		=	78,
88 	RIGHT			=	79,
89 	LEFT			=	80,
90 	DOWN			=	81,
91 	UP				=	82,
92 
93 	NUMLOCK			=	83,
94 	NP_DIVIDE		=	84,
95 	NP_MULTIPLY		=	85,
96 	NP_MINUS		=	86,
97 	NP_PLUS			=	87,
98 	NP_ENTER		=	88,
99 
100 	np1				=	89,
101 	np2				=	90,
102 	np3				=	91,
103 	np4				=	92,
104 	np5				=	93,
105 	np6				=	94,
106 	np7				=	95,
107 	np8				=	96,
108 	np9				=	97,
109 	np0				=	98,
110 
111 	NP_PERIOD		=	99,
112 
113 	NONUSBACKSLASH	=	100,
114 	APPLICATION		=	101,
115 
116 	NP_EQUALS		=	102,
117 
118 	F13				=	104,
119 	F14				=	105,
120 	F15				=	106,
121 	F16				=	107,
122 	F17				=	108,
123 	F18				=	109,
124 	F19				=	110,
125 	F20				=	111,
126 	F21				=	112,
127 	F22				=	113,
128 	F23				=	114,
129 	F24				=	115,
130 
131 	EXECUTE			=	116,
132 	HELP			=	117,
133 	MENU			=	118,
134 	SELECT			=	119,
135 	STOP			=	120,
136 	REDO			=	121,
137 	UNDO			=	122,
138 	CUT				=	123,
139 	COPY			=	124,
140 	PASTE			=	125,
141 	FIND			=	126,
142 	MUTE			=	127,
143 	VOLUME_UP		=	128,
144 	VOLUME_DOWN		=	129,
145 
146 	NP_COMMA		=	133,
147 	NP_EQUALSAS400	=	134,
148 
149 	INTERNATIONAL1	=	135,
150 	INTERNATIONAL2	=	136,
151 	INTERNATIONAL3	=	137,
152 	INTERNATIONAL4	=	138,
153 	INTERNATIONAL5	=	139,
154 	INTERNATIONAL6	=	140,
155 	INTERNATIONAL7	=	141,
156 	INTERNATIONAL8	=	142,
157 	INTERNATIONAL9	=	143,
158 
159 	LANGUAGE1		=	144,
160 	LANGUAGE2		=	145,
161 	LANGUAGE3		=	146,
162 	LANGUAGE4		=	147,
163 	LANGUAGE5		=	148,
164 	LANGUAGE6		=	149,
165 	LANGUAGE7		=	150,
166 	LANGUAGE8		=	151,
167 	LANGUAGE9		=	152,
168 
169 	ALTERASE		=	153,
170 	SYSREQ			=	154,
171 	CANCEL			=	155,
172 	PRIOR			=	157,
173 	ENTER2			=	158,
174 	SEPARATOR		=	159,
175 	OUT				=	160,
176 	OPERATE			=	161,
177 	CLEARAGAIN		=	162,
178 	CRSEL			=	163,
179 	EXSEL			=	164,
180 
181 	NP00			=	176,
182 	NP000			=	177,
183 	THROUSANDSEPAR	=	178,
184 	HUNDREDSSEPAR	=	179,
185 	CURRENCYUNIT	=	180,
186 	CURRENCYSUBUNIT	=	181,
187 	NP_LEFTPAREN	=	182,
188 	NP_RIGHTPAREN	=	183,
189 	NP_LEFTBRACE	=	184,
190 	NP_RIGHTBRACE	=	185,
191 	NP_TAB			=	186,
192 	NP_BACKSPACE	=	187,
193 	NP_A			=	188,
194 	NP_B			=	189,
195 	NP_C			=	190,
196 	NP_D			=	191,
197 	NP_E			=	192,
198 	NP_F			=	193,
199 	NP_XOR			=	194,
200 	NP_POWER		=	195,
201 	NP_PERCENT		=	196,
202 	NP_LESS			=	197,
203 	NP_GREATER		=	198,
204 	NP_AMPERSAND	=	199,
205 	NP_DBAMPERSAND	=	200,
206 	NP_VERTICALBAR	=	201,
207 	NP_DBVERTICALBAR=	202,
208 	NP_COLON		=	203,
209 	NP_HASH			=	204,
210 	NP_SPACE		=	205,
211 	NP_AT			=	206,
212 	NP_EXCLAM		=	207,
213 	NP_MEMSTORE		=	208,
214 	NP_MEMRECALL	=	209,
215 	NP_MEMCLEAR		=	210,
216 	NP_MEMADD		=	211,
217 	NP_MEMSUBSTRACT	=	212,
218 	NP_MEMMULTIPLY	=	213,
219 	NP_MEMDIVIDE	=	214,
220 	NP_PLUSMINUS	=	215,
221 	NP_CLEAR		=	216,
222 	NP_CLEARENTRY	=	217,
223 	NP_BINARY		=	218,
224 	NP_OCTAL		=	219,
225 	NP_DECIMAL		=	220,
226 	NP_HEXADECIMAL	=	221,
227 
228 	LCTRL			=	224,
229 	LSHIFT			=	225,
230 	LALT			=	226,
231 	LGUI			=	227,
232 	RCTRL			=	228,
233 	RSHIFT			=	229,
234 	RALT			=	230,
235 	RGUI			=	231,
236 
237 	MEDIAPLAY		=	232,
238 	MEDIASTOPCD		=	233,
239 	MEDIAPREV		=	234,
240 	MEDIANEXT		=	235,
241 	MEDIAEJECT		=	236,
242 	MEDIAVOLUP		=	237,
243 	MEDIAVOLDOWN	=	238,
244 	MEDIAMUTE		=	239,
245 
246 	MEDIAWWW 		=	0xf0,
247 	MEDIABACK 		=	0xf1,
248 	MEDIAFORWARD 	=	0xf2,
249 	MEDIASTOP 		=	0xf3,
250 	MEDIAFIND 		=	0xf4,
251 	MEDIASCROLLUP 	=	0xf5,
252 	MEDIASCROLLDOWN =	0xf6,
253 	MEDIAEDIT 		=	0xf7,
254 	MEDIASLEEP 		=	0xf8,
255 	MEDIACOFFEE 	=	0xf9,
256 	MEDIAREFRESH 	=	0xfa,
257 	MEDIACALC 		=	0xfb,
258 	//Not sure about these, but I can't find their respected USB HID scancodes, so I just added these here.
259 	//There's a faint chance that LAUNCHAPP1 and 2 are MEDIAEDIT and  MEDIACALC, but I can't find anything about them.
260 	//Note that these might no longer will exist as are currently in the future.
261 	MEDIAMAIL		=	0x100,
262 	MEDIASELECT		=	0x101,
263 	LAUNCHAPP1		=	0x102,
264 	LAUNCHAPP2		=	0x103,
265 }
266 
267 /**
268  * Translates OS native scancodes to standard ones.
269  */
270 package uint translateSC(uint input) @nogc @safe pure nothrow {
271 	version (Windows) {
272 		switch (input) {
273 			case 0x08:
274 				return ScanCode.BACKSPACE;
275 			case 0x09:
276 				return ScanCode.TAB;
277 			case 0x0c:
278 				return ScanCode.CLEARAGAIN;
279 			case 0x0d:
280 				return ScanCode.ENTER;
281 			case 0x13:
282 				return ScanCode.PAUSE;
283 			case 0x14:
284 				return ScanCode.CAPSLOCK;
285 			case 0x15:
286 				return ScanCode.LANGUAGE1;
287 			case 0x1b:
288 				return ScanCode.ESCAPE;
289 			case 0x19:
290 				return ScanCode.LANGUAGE2;
291 			case 0x20:
292 				return ScanCode.SPACE;
293 			case 0x21:
294 				return ScanCode.PAGEUP;
295 			case 0x22:
296 				return ScanCode.PAGEDOWN;
297 			case 0x23:
298 				return ScanCode.END;
299 			case 0x24:
300 				return ScanCode.HOME;
301 			case 0x25:
302 				return ScanCode.LEFT;
303 			case 0x26:
304 				return ScanCode.UP;
305 			case 0x27:
306 				return ScanCode.RIGHT;
307 			case 0x28:
308 				return ScanCode.DOWN;
309 			case 0x29:
310 				return ScanCode.SELECT;
311 			case 0x2c:
312 				return ScanCode.PRINTSCREEN;
313 			case 0x2d:
314 				return ScanCode.INSERT;
315 			case 0x2e:
316 				return ScanCode.DELETE;
317 			case 0x2f:
318 				return ScanCode.HELP;
319 			case 0x30:						//Numeric-block
320 				return ScanCode.n0;
321 			case 0x31: .. case 0x39:		//Numeric-block
322 				return input - 0x30 + 30;
323 			case 0x41: .. case 0x5A:		//Alpha-block
324 				return input - 0x41 + 4;
325 			case 0x5b:
326 				return ScanCode.LGUI;
327 			case 0x5c:
328 				return ScanCode.RGUI;
329 			case 0x5d:
330 				return ScanCode.APPLICATION;
331 			case 0x5f:
332 				return ScanCode.MEDIASLEEP;
333 			case 0x60:						//Numpad
334 				return ScanCode.np0;
335 			case 0x61: .. case 0x69:		//Numpad
336 				return input - 0x61 + ScanCode.np1;
337 			case 0x6a:
338 				return ScanCode.NP_MULTIPLY;
339 			case 0x6b:
340 				return ScanCode.NP_PLUS;
341 			case 0x6c:
342 				return ScanCode.NP_COMMA;
343 			case 0x6d:
344 				return ScanCode.NP_MINUS;
345 			case 0x6e:
346 				return ScanCode.NP_DECIMAL;
347 			case 0x6f:
348 				return ScanCode.NP_DIVIDE;
349 			case 0x70: .. case 0x7B:		//Function row
350 				return input - 0x70 + 58;
351 			case 0x7C: .. case 0x87:		//Extended function row
352 				return input - 0x7C + 104;
353 			case 0x90:
354 				return ScanCode.NUMLOCK;
355 			case 0x91:
356 				return ScanCode.SCROLLLOCK;
357 			case 0xA0:
358 				return ScanCode.LSHIFT;
359 			case 0xa1:
360 				return ScanCode.RSHIFT;
361 			case 0xa2:
362 				return ScanCode.LCTRL;
363 			case 0xa3:
364 				return ScanCode.RCTRL;
365 			case 0xa4:
366 				return ScanCode.LALT;
367 			case 0xa5:
368 				return ScanCode.RALT;
369 			case 0xa6:
370 				return ScanCode.MEDIABACK;
371 			case 0xa7:
372 				return ScanCode.MEDIAFORWARD;
373 			case 0xa8:
374 				return ScanCode.MEDIAREFRESH;
375 			case 0xa9:
376 				return ScanCode.STOP;
377 			case 0xaa:
378 				return ScanCode.MEDIAFIND;
379 			case 0xab:
380 				return ScanCode.MEDIACOFFEE;
381 			case 0xac:
382 				return ScanCode.MEDIAWWW;
383 			case 0xad:
384 				return ScanCode.MUTE;
385 			case 0xae:
386 				return ScanCode.VOLUME_DOWN;
387 			case 0xaf:
388 				return ScanCode.VOLUME_UP;
389 			case 0xb0:
390 				return ScanCode.MEDIANEXT;
391 			case 0xb1:
392 				return ScanCode.MEDIAPREV;
393 			case 0xb2:
394 				return ScanCode.MEDIASTOP;
395 			case 0xb3:
396 				return ScanCode.MEDIAPLAY;
397 			case 0xb4:
398 				return ScanCode.MEDIAMAIL;
399 			case 0xb5:
400 				return ScanCode.MEDIASELECT;
401 			case 0xb6:
402 				return ScanCode.LAUNCHAPP1;
403 			case 0xb7:
404 				return ScanCode.LAUNCHAPP2;
405 
406 			case 0xba:
407 				return ScanCode.SEMICOLON;
408 			case 0xbb:
409 				return ScanCode.EQUALS;
410 			case 0xbc:
411 				return ScanCode.COMMA;
412 			case 0xbd:
413 				return ScanCode.MINUS;
414 			case 0xbe:
415 				return ScanCode.PERIOD;
416 			case 0xbf:
417 				return ScanCode.SLASH;
418 			case 0xc0:
419 				return ScanCode.GRAVE;
420 			case 0xdb:
421 				return ScanCode.LEFTBRACKET;
422 			case 0xdc:
423 				return ScanCode.BACKSLASH;
424 			case 0xdd:
425 				return ScanCode.RIGHTBRACKET;
426 			case 0xde:
427 				return ScanCode.APOSTROPHE;
428 			case 0xdf:
429 				return ScanCode.NONUSHASH;
430 			case 0xe2:
431 				return ScanCode.NONUSBACKSLASH;
432 			default:
433 				return ScanCode.init;
434 		}
435 	}
436 }