7a9f05abb7672844199a151084e1ee4c4ac3d73e
[reactos.git] / reactos / lib / kbduk / kbduk.c
1 /*
2 * ReactOS USASCII Keyboard layout
3 * Copyright (C) 2003 ReactOS
4 * License: LGPL, see: LGPL.txt
5 *
6 * Thanks to: http://www.barcodeman.com/altek/mule/scandoc.php
7 * and http://win.tue.nl/~aeb/linux/kbd/scancodes-1.html
8 */
9
10 #include <windows.h>
11 #include <internal/kbd.h>
12
13 #ifdef _M_IA64
14 #define ROSDATA static __declspec(allocate(".data"))
15 #else
16 #ifdef _MSC_VER
17 #pragma data_seg(".data")
18 #define ROSDATA static
19 #else
20 #define ROSDATA static __attribute__((section(".data")))
21 #endif
22 #endif
23
24 #define VK_EMPTY 0xff /* The non-existent VK */
25 #define KSHIFT 0x001 /* Shift modifier */
26 #define KCTRL 0x002 /* Ctrl modifier */
27 #define KALT 0x004 /* Alt modifier */
28 #define KEXT 0x100 /* Extended key code */
29 #define KMULTI 0x200 /* Multi-key */
30 #define KSPEC 0x400 /* Special key */
31 #define KNUMP 0x800 /* Number-pad */
32 #define KNUMS 0xc00 /* Special + number pad */
33 #define KMEXT 0x300 /* Multi + ext */
34
35 ROSDATA USHORT scancode_to_vk[] = {
36 /* Numbers Row */
37 /* - 00 - */
38 /* 1 ... 2 ... 3 ... 4 ... */
39 VK_EMPTY, VK_ESCAPE, '1', '2',
40 '3', '4', '5', '6',
41 '7', '8', '9', '0',
42 VK_OEM_MINUS, VK_OEM_PLUS, VK_BACK,
43 /* - 0f - */
44 /* First Letters Row */
45 VK_TAB, 'Q', 'W', 'E',
46 'R', 'T', 'Y', 'U',
47 'I', 'O', 'P',
48 VK_OEM_4, VK_OEM_6, VK_RETURN,
49 /* - 1d - */
50 /* Second Letters Row */
51 VK_LCONTROL,
52 'A', 'S', 'D', 'F',
53 'G', 'H', 'J', 'K',
54 'L', VK_OEM_1, VK_OEM_3, VK_OEM_8,
55 VK_LSHIFT, VK_OEM_7,
56 /* - 2c - */
57 /* Third letters row */
58 'Z', 'X', 'C', 'V',
59 'B', 'N', 'M', VK_OEM_COMMA,
60 VK_OEM_PERIOD,VK_OEM_2, VK_RSHIFT|KEXT,
61 /* - 37 - */
62 /* Bottom Row */
63 VK_MULTIPLY, VK_MENU, VK_SPACE, VK_CAPITAL,
64
65 /* - 3b - */
66 /* F-Keys */
67 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
68 VK_F7, VK_F8, VK_F9, VK_F10,
69 /* - 45 - */
70 /* Locks */
71 VK_NUMLOCK | KMEXT,
72 VK_SCROLL | KMULTI,
73 /* - 47 - */
74 /* Number-Pad */
75 VK_HOME | KNUMS, VK_UP | KNUMS, VK_PRIOR | KNUMS, VK_SUBTRACT,
76 VK_LEFT | KNUMS, VK_CLEAR | KNUMS, VK_RIGHT | KNUMS, VK_ADD,
77 VK_END | KNUMS, VK_DOWN | KNUMS, VK_NEXT | KNUMS,
78 VK_INSERT | KNUMS, VK_DELETE | KNUMS,
79 /* - 54 - */
80 /* Presumably PrtSc */
81 VK_SNAPSHOT,
82 /* - 55 - */
83 /* Oddities, and the remaining standard F-Keys */
84 VK_EMPTY, VK_OEM_5, VK_F11, VK_F12,
85 /* - 59 - */
86 VK_CLEAR, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, /* EREOF */
87 VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, /* ZOOM */
88 VK_HELP,
89 /* - 64 - */
90 /* Even more F-Keys (for example, NCR keyboards from the early 90's) */
91 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18, VK_F19, VK_F20,
92 VK_F21, VK_F22, VK_F23,
93 /* - 6f - */
94 /* Not sure who uses these codes */
95 VK_EMPTY, VK_EMPTY, VK_EMPTY,
96 /* - 72 - */
97 VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY,
98 /* - 76 - */
99 /* One more f-key */
100 VK_F24,
101 /* - 77 - */
102 VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY,
103 VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, /* PA1 */
104 VK_EMPTY,
105 /* - 80 - */
106 0
107 };
108
109 ROSDATA VSC_VK extcode0_to_vk[] = {
110 {0x1c, VK_RETURN|KEXT}, //Keypad return
111 {0x1d, VK_RCONTROL|KEXT},//Right control key
112 {0x35, VK_DIVIDE|KEXT}, // Numpad div
113 {0x38, VK_RMENU|KEXT}, //AltGr?
114 {0, 0},
115 };
116
117 ROSDATA VSC_VK extcode1_to_vk[] = {
118 { 0, 0 },
119 };
120
121 ROSDATA VK_TO_BIT modifier_keys[] = {
122 { VK_SHIFT, KSHIFT },
123 { VK_CONTROL, KCTRL },
124 { VK_MENU, KALT },
125 { 0, 0 }
126 };
127
128 ROSDATA MODIFIERS modifier_bits = {
129 modifier_keys,
130 7,
131 { 0, 1, 2, 3 ,0, 0,4,5} /* Modifier bit order, NONE, SHIFT, CTRL, SHIFT+CTRL,ALT(not used),SHIFT-ALT (not used), CTR+ALT, SHIFT-CTRL-ALT*/
132 };
133
134 #define NOCAPS 0
135 #define CAPS KSHIFT /* Caps -> shift */
136
137 ROSDATA VK_TO_WCHARS2 key_to_chars_2mod[] = {
138 /* Normal vs Shifted */
139 /* The numbers */
140 { '1', NOCAPS, {'1', '!'} },
141 { '2', NOCAPS, {'2', '\"'} },
142 { '3', NOCAPS, {'3', 0xa3} },
143 { '5', NOCAPS, {'5', '%'} },
144 { '7', NOCAPS, {'7', '&'} },
145 { '8', NOCAPS, {'8', '*'} },
146 { '9', NOCAPS, {'9', '('} },
147 { '0', NOCAPS, {'0', ')'} },
148 { VK_OEM_PLUS ,NOCAPS, {'=', '+'} },
149 /* First letter row */
150 { 'Q', CAPS, {'q', 'Q'} },
151 { 'W', CAPS, {'w', 'W'} },
152 { 'R', CAPS, {'r', 'R'} },
153 { 'T', CAPS, {'t', 'T'} },
154 { 'Y', CAPS, {'y', 'Y'} },
155 { 'P', CAPS, {'p', 'P'} },
156 /* Second letter row */
157 { 'S', CAPS, {'s', 'S'} },
158 { 'D', CAPS, {'d', 'D'} },
159 { 'F', CAPS, {'f', 'F'} },
160 { 'G', CAPS, {'g', 'G'} },
161 { 'H', CAPS, {'h', 'H'} },
162 { 'J', CAPS, {'j', 'J'} },
163 { 'K', CAPS, {'k', 'K'} },
164 { 'L', CAPS, {'l', 'L'} },
165 { VK_OEM_1 ,NOCAPS, {';', ':'} },
166
167 /* Third letter row */
168 { 'Z', CAPS, {'z', 'Z'} },
169 { 'X', CAPS, {'x', 'X'} },
170 { 'C', CAPS, {'c', 'C'} },
171 { 'V', CAPS, {'v', 'V'} },
172 { 'B', CAPS, {'b', 'B'} },
173 { 'N', CAPS, {'n', 'N'} },
174 { 'M', CAPS, {'m', 'M'} },
175 { VK_OEM_COMMA, NOCAPS, {',', '<'} },
176 { VK_OEM_PERIOD, NOCAPS, {'.', '>'} },
177 { VK_OEM_2, NOCAPS, {'/', '?'} },
178
179
180 /* Keys that do not have shift states */
181 { VK_TAB, NOCAPS, {'\t','\t'} },
182 { VK_ADD, NOCAPS, {'+', '+'} },
183 { VK_SUBTRACT, NOCAPS, {'-', '-'} },
184 { VK_MULTIPLY, NOCAPS, {'*', '*'} },
185 { VK_DIVIDE, NOCAPS, {'/', '/'} },
186 { VK_ESCAPE, NOCAPS, {'\x1b','\x1b'} },
187 { VK_SPACE, NOCAPS, {' ', ' '} },
188 { 0, 0 }
189 };
190
191 ROSDATA VK_TO_WCHARS3 key_to_chars_3mod[] = {
192 /* Normal, Shifted, Ctrl */
193 /* Legacy (telnet-style) ascii escapes */
194 { VK_OEM_4, NOCAPS, {'[', '{', 0x1b} },
195 { VK_OEM_6, NOCAPS, {']', '}', 0x1d} },
196 { VK_OEM_7, NOCAPS, {'#', '~', 0x1c} },
197 { VK_OEM_5, 0, {'\\', '|', 0x1c} },
198 { VK_RETURN, 0, {'\r', '\r', '\n'} },
199 { 0, 0 }
200 };
201
202 ROSDATA VK_TO_WCHARS4 key_to_chars_4mod[] = {
203 /* Normal, Shifted, Ctrl, C-Shift */
204 /* Legacy Ascii generators */
205
206 { '6', NOCAPS, {'6', '^', WCH_NONE, 0x1e} },
207 { VK_OEM_MINUS, NOCAPS, {'-', '_', WCH_NONE, 0x1f} },
208 { VK_OEM_3, NOCAPS, {'\'', '@', WCH_NONE, 0x00} },
209 { 0, 0 }
210 };
211
212 ROSDATA VK_TO_WCHARS5 key_to_chars_5mod[] = {
213 /* Normal, Shifted, Ctrl, Sh-Ctrl,Sh-Alt,Ctl-Alt */
214 /* Ctrl-sh-6 generates RS */
215 {VK_OEM_8, NOCAPS, {'`', 0x00ac, WCH_NONE, WCH_NONE, 0xa6} },
216 { '4', NOCAPS, {'4', '$', WCH_NONE, WCH_NONE, 0x20ac} },
217 { 0, 0 }
218 };
219
220 ROSDATA VK_TO_WCHARS6 key_to_chars_6mod[] = {
221 /* Normal, Shifted, Ctrl, Sh-Ctrl,Sh-Alt,Ctl-Alt,Ctl-Sh-Alt */
222
223 { 'E', CAPS, {'e', 'E', WCH_NONE, WCH_NONE, 0x00e9, 0x00c9} },
224 { 'U', CAPS, {'u', 'U', WCH_NONE, WCH_NONE, 0x00fa, 0x00da} },
225 { 'I', CAPS, {'i', 'I', WCH_NONE, WCH_NONE, 0x00ed, 0x00cd} },
226 { 'O', CAPS, {'o', 'O', WCH_NONE, WCH_NONE, 0x00f3, 0x00d3} },
227 { 'A', CAPS, {'a', 'A', WCH_NONE, WCH_NONE, 0x00e1, 0x00c1} },
228 { 0, 0 }
229 };
230
231 ROSDATA VK_TO_WCHARS1 keypad_numbers[] = {
232 { VK_DECIMAL, 0, {'.'} },
233 { VK_NUMPAD0, 0, {'0'} },
234 { VK_NUMPAD1, 0, {'1'} },
235 { VK_NUMPAD2, 0, {'2'} },
236 { VK_NUMPAD3, 0, {'3'} },
237 { VK_NUMPAD4, 0, {'4'} },
238 { VK_NUMPAD5, 0, {'5'} },
239 { VK_NUMPAD6, 0, {'6'} },
240 { VK_NUMPAD7, 0, {'7'} },
241 { VK_NUMPAD8, 0, {'8'} },
242 { VK_NUMPAD9, 0, {'9'} },
243 { VK_BACK, 0, {'\010'} },
244 { 0, 0 }
245 };
246
247 #define vk_master(n,x) { (PVK_TO_WCHARS1)x, n, sizeof(x[0]) }
248
249 ROSDATA VK_TO_WCHAR_TABLE vk_to_wchar_master_table[] = {
250 vk_master(1,keypad_numbers),
251 vk_master(2,key_to_chars_2mod),
252 vk_master(3,key_to_chars_3mod),
253 vk_master(4,key_to_chars_4mod),
254 vk_master(5,key_to_chars_5mod),
255 vk_master(6,key_to_chars_6mod),
256 { 0,0,0 }
257 };
258
259 ROSDATA VSC_LPWSTR key_names[] = {
260 { 0x00, L"" },
261 { 0x01, L"Esc" },
262 { 0x0e, L"Backspace" },
263 { 0x0f, L"Tab" },
264 { 0x1c, L"Enter" },
265 { 0x1d, L"Ctrl" },
266 { 0x2a, L"Shift" },
267 { 0x36, L"Right Shift" },
268 { 0x37, L"Num *" },
269 { 0x38, L"Alt" },
270 { 0x39, L"Space" },
271 { 0x3a, L"Caps Lock" },
272 { 0x3b, L"F1" },
273 { 0x3c, L"F2" },
274 { 0x3d, L"F3" },
275 { 0x3e, L"F4" },
276 { 0x3f, L"F5" },
277 { 0x40, L"F6" },
278 { 0x41, L"F7" },
279 { 0x42, L"F8" },
280 { 0x43, L"F9" },
281 { 0x44, L"F10" },
282 { 0x45, L"Pause" },
283 { 0x46, L"Scroll Lock" },
284 { 0x47, L"Num 7" },
285 { 0x48, L"Num 8" },
286 { 0x49, L"Num 9" },
287 { 0x4a, L"Num -" },
288 { 0x4b, L"Num 4" },
289 { 0x4c, L"Num 5" },
290 { 0x4d, L"Num 6" },
291 { 0x4e, L"Num +" },
292 { 0x4f, L"Num 1" },
293 { 0x50, L"Num 2" },
294 { 0x51, L"Num 3" },
295 { 0x52, L"Num 0" },
296 { 0x53, L"Num Del" },
297 { 0x54, L"Sys Req" },
298 { 0x57, L"F11" },
299 { 0x58, L"F12" },
300 { 0x7c, L"F13" },
301 { 0x7d, L"F14" },
302 { 0x7e, L"F15" },
303 { 0x7f, L"F16" },
304 { 0x80, L"F17" },
305 { 0x81, L"F18" },
306 { 0x82, L"F19" },
307 { 0x83, L"F20" },
308 { 0x84, L"F21" },
309 { 0x85, L"F22" },
310 { 0x86, L"F23" },
311 { 0x87, L"F24" },
312 { 0, NULL },
313 };
314
315 ROSDATA VSC_LPWSTR extended_key_names[] = {
316 { 0x1c, L"Num Enter" },
317 { 0x1d, L"Right Ctrl" },
318 { 0x35, L"Num /" },
319 { 0x37, L"Prnt Scrn" },
320 { 0x38, L"Right Alt" },
321 { 0x45, L"Num Lock" },
322 { 0x46, L"Break" },
323 { 0x47, L"Home" },
324 { 0x48, L"Up" },
325 { 0x49, L"Page Up" },
326 { 0x4a, L"Left" },
327 { 0x4c, L"Center" },
328 { 0x4d, L"Right" },
329 { 0x4f, L"End" },
330 { 0x50, L"Down" },
331 { 0x51, L"Page Down" },
332 { 0x52, L"Insert" },
333 { 0x53, L"Delete" },
334 { 0x54, L"<ReactOS>" },
335 { 0x55, L"Help" },
336 { 0x56, L"Left Windows" },
337 { 0x5b, L"Right Windows" },
338 { 0, NULL },
339 };
340
341 /* Finally, the master table */
342 ROSDATA KBDTABLES keyboard_layout_table = {
343 /* modifier assignments */
344 &modifier_bits,
345
346 /* character from vk tables */
347 vk_to_wchar_master_table,
348
349 /* diacritical marks -- currently implemented by wine code */
350 /* English doesn't have any, anyway */
351 NULL,
352
353 /* Key names */
354 (VSC_LPWSTR *)key_names,
355 (VSC_LPWSTR *)extended_key_names,
356 NULL, /* Dead key names */
357
358 /* scan code to virtual key maps */
359 scancode_to_vk,
360 sizeof(scancode_to_vk) / sizeof(scancode_to_vk[0]),
361 extcode0_to_vk,
362 extcode1_to_vk,
363
364
365 MAKELONG(0,1), /* Version 1.0 */
366
367 /* Ligatures -- English doesn't have any */
368 0,
369 0,
370 NULL
371 };
372
373 PKBDTABLES STDCALL KbdLayerDescriptor() {
374 return &keyboard_layout_table;
375 }
376