Added kbdhe. Was missing.
[reactos.git] / reactos / lib / keyboard / kbdhu / kbdhu.c
1 /*
2 * ReactOS HUASCII 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_7, VK_OEM_3,
55 VK_LSHIFT, VK_OEM_5,
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,
61 /* - 37 - */
62 /* Bottom Row */
63 VK_MULTIPLY, VK_LMENU, 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_EMPTY, 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 { 0, 0 },
111 };
112
113 ROSDATA VSC_VK extcode1_to_vk[] = {
114 { 0, 0 },
115 };
116
117 ROSDATA VK_TO_BIT modifier_keys[] = {
118 { VK_SHIFT, KSHIFT },
119 { VK_CONTROL, KCTRL },
120 { VK_MENU, KALT },
121 { 0, 0 }
122 };
123
124 ROSDATA MODIFIERS modifier_bits = {
125 modifier_keys,
126 3,
127 { 0, 1, 2, 3 } /* Modifier bit order, NONE, SHIFT, CTRL, ALT */
128 };
129
130 #define NOCAPS 0
131 #define CAPS KSHIFT /* Caps -> shift */
132
133 ROSDATA VK_TO_WCHARS2 key_to_chars_2mod[] = {
134 /* Normal vs Shifted */
135 /* The numbers */
136 { '1', NOCAPS, {'1', '\''} },
137 /* Ctrl-2 generates NUL */
138 { '3', NOCAPS, {'3', '+'} },
139 { '4', NOCAPS, {'4', '!'} },
140 { '5', NOCAPS, {'5', '%'} },
141 /* Ctrl-6 generates RS */
142 { '7', NOCAPS, {'7', '='} },
143 { '8', NOCAPS, {'8', '('} },
144 { '9', NOCAPS, {'9', ')'} },
145 { '0', NOCAPS, {'ö', 'Ö'} },
146 /* First letter row */
147 { 'Q', CAPS, {'q', 'Q'} },
148 { 'W', CAPS, {'w', 'W'} },
149 { 'E', CAPS, {'e', 'E'} },
150 { 'R', CAPS, {'r', 'R'} },
151 { 'T', CAPS, {'t', 'T'} },
152 { 'Y', CAPS, {'y', 'Y'} },
153 { 'U', CAPS, {'u', 'U'} },
154 { 'I', CAPS, {'i', 'I'} },
155 { 'O', CAPS, {'o', 'O'} },
156 { 'P', CAPS, {'p', 'P'} },
157 /* Second letter row */
158 { 'A', CAPS, {'a', 'A'} },
159 { 'S', CAPS, {'s', 'S'} },
160 { 'D', CAPS, {'d', 'D'} },
161 { 'F', CAPS, {'f', 'F'} },
162 { 'G', CAPS, {'g', 'G'} },
163 { 'H', CAPS, {'h', 'H'} },
164 { 'J', CAPS, {'j', 'J'} },
165 { 'K', CAPS, {'k', 'K'} },
166 { 'L', CAPS, {'l', 'L'} },
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
176 /* Specials */
177 /* Ctrl-_ generates US */
178 { VK_OEM_PLUS ,NOCAPS, {'ó', 'Ó'} },
179 { VK_OEM_1 ,NOCAPS, {'é', 'É'} },
180 { VK_OEM_7 ,NOCAPS, {'û', 'Û'} },
181 { VK_OEM_3 ,NOCAPS, {'0', '§'} },
182 { VK_OEM_COMMA ,NOCAPS, {',', '?'} },
183 { VK_OEM_PERIOD ,NOCAPS, {'.', ':'} },
184 { VK_OEM_2 ,NOCAPS, {'-', '_'} },
185 /* Keys that do not have shift states */
186 { VK_TAB ,NOCAPS, {'\t','\t'} },
187 { VK_ADD ,NOCAPS, {'+', '+'} },
188 { VK_SUBTRACT,NOCAPS, {'-', '-'} },
189 { VK_MULTIPLY,NOCAPS, {'*', '*'} },
190 { VK_DIVIDE ,NOCAPS, {'/', '/'} },
191 { VK_ESCAPE ,NOCAPS, {'\x1b','\x1b'} },
192 { VK_SPACE ,NOCAPS, {' ', ' '} },
193 { 0, 0 }
194 };
195
196 ROSDATA VK_TO_WCHARS3 key_to_chars_3mod[] = {
197 /* Normal, Shifted, Ctrl */
198 /* Legacy (telnet-style) ascii escapes */
199 { VK_OEM_4, 0, {'õ', 'Õ', 0x1b /* ESC */} },
200 { VK_OEM_6, 0, {'ú', 'Ú', 0x1d /* GS */} },
201 { VK_OEM_5, 0, {'û','Û', 0x1c /* FS */} },
202 { VK_RETURN,0, {'\r', '\r', '\n'} },
203 { 0,0 }
204 };
205
206 ROSDATA VK_TO_WCHARS4 key_to_chars_4mod[] = {
207 /* Normal, Shifted, Ctrl, C-S-x */
208 /* Legacy Ascii generators */
209 { '2', NOCAPS, {'2', '"', WCH_NONE, 0} },
210 { '6', NOCAPS, {'6', '/', WCH_NONE, 0x1e /* RS */} },
211 { VK_OEM_MINUS, NOCAPS, {'-', '_', WCH_NONE, 0x1f /* US */} },
212 { 0, 0 }
213 };
214
215 ROSDATA VK_TO_WCHARS1 keypad_numbers[] = {
216 { VK_NUMPAD0, 0, {'0'} },
217 { VK_NUMPAD1, 0, {'1'} },
218 { VK_NUMPAD2, 0, {'2'} },
219 { VK_NUMPAD3, 0, {'3'} },
220 { VK_NUMPAD4, 0, {'4'} },
221 { VK_NUMPAD5, 0, {'5'} },
222 { VK_NUMPAD6, 0, {'6'} },
223 { VK_NUMPAD7, 0, {'7'} },
224 { VK_NUMPAD8, 0, {'8'} },
225 { VK_NUMPAD9, 0, {'9'} },
226 { VK_DECIMAL, 0, {'.'} },
227 { VK_BACK, 0, {'\010'} },
228 { 0,0 }
229 };
230
231 #define vk_master(n,x) { (PVK_TO_WCHARS1)x, n, sizeof(x[0]) }
232
233 ROSDATA VK_TO_WCHAR_TABLE vk_to_wchar_master_table[] = {
234 vk_master(1,keypad_numbers),
235 vk_master(2,key_to_chars_2mod),
236 vk_master(3,key_to_chars_3mod),
237 vk_master(4,key_to_chars_4mod),
238 { 0,0,0 }
239 };
240
241 ROSDATA VSC_LPWSTR key_names[] = {
242 { 0x00, L"" },
243 { 0x01, L"Esc" },
244 { 0x0e, L"Backspace" },
245 { 0x0f, L"Tab" },
246 { 0x1c, L"Enter" },
247 { 0x1d, L"Ctrl" },
248 { 0x2a, L"Shift" },
249 { 0x36, L"Right Shift" },
250 { 0x37, L"Num *" },
251 { 0x38, L"Alt" },
252 { 0x39, L"Space" },
253 { 0x3a, L"Caps Lock" },
254 { 0x3b, L"F1" },
255 { 0x3c, L"F2" },
256 { 0x3d, L"F3" },
257 { 0x3e, L"F4" },
258 { 0x3f, L"F5" },
259 { 0x40, L"F6" },
260 { 0x41, L"F7" },
261 { 0x42, L"F8" },
262 { 0x43, L"F9" },
263 { 0x44, L"F10" },
264 { 0x45, L"Pause" },
265 { 0x46, L"Scroll Lock" },
266 { 0x47, L"Num 7" },
267 { 0x48, L"Num 8" },
268 { 0x49, L"Num 9" },
269 { 0x4a, L"Num -" },
270 { 0x4b, L"Num 4" },
271 { 0x4c, L"Num 5" },
272 { 0x4d, L"Num 6" },
273 { 0x4e, L"Num +" },
274 { 0x4f, L"Num 1" },
275 { 0x50, L"Num 2" },
276 { 0x51, L"Num 3" },
277 { 0x52, L"Num 0" },
278 { 0x53, L"Num Del" },
279 { 0x54, L"Sys Req" },
280 { 0x57, L"F11" },
281 { 0x58, L"F12" },
282 { 0x7c, L"F13" },
283 { 0x7d, L"F14" },
284 { 0x7e, L"F15" },
285 { 0x7f, L"F16" },
286 { 0x80, L"F17" },
287 { 0x81, L"F18" },
288 { 0x82, L"F19" },
289 { 0x83, L"F20" },
290 { 0x84, L"F21" },
291 { 0x85, L"F22" },
292 { 0x86, L"F23" },
293 { 0x87, L"F24" },
294 { 0, NULL },
295 };
296
297 ROSDATA VSC_LPWSTR extended_key_names[] = {
298 { 0x1c, L"Num Enter" },
299 { 0x1d, L"Right Ctrl" },
300 { 0x35, L"Num /" },
301 { 0x37, L"Prnt Scrn" },
302 { 0x38, L"Right Alt" },
303 { 0x45, L"Num Lock" },
304 { 0x46, L"Break" },
305 { 0x47, L"Home" },
306 { 0x48, L"Up" },
307 { 0x49, L"Page Up" },
308 { 0x4a, L"Left" },
309 { 0x4c, L"Center" },
310 { 0x4d, L"Right" },
311 { 0x4f, L"End" },
312 { 0x50, L"Down" },
313 { 0x51, L"Page Down" },
314 { 0x52, L"Insert" },
315 { 0x53, L"Delete" },
316 { 0x54, L"<ReactOS>" },
317 { 0x55, L"Help" },
318 { 0x56, L"Left Windows" },
319 { 0x5b, L"Right Windows" },
320 { 0, NULL },
321 };
322
323 /* Finally, the master table */
324 ROSDATA KBDTABLES keyboard_layout_table = {
325 /* modifier assignments */
326 &modifier_bits,
327
328 /* character from vk tables */
329 vk_to_wchar_master_table,
330
331 /* diacritical marks -- currently implemented by wine code */
332 /* English doesn't have any, anyway */
333 NULL,
334
335 /* Key names */
336 (VSC_LPWSTR *)key_names,
337 (VSC_LPWSTR *)extended_key_names,
338 NULL, /* Dead key names */
339
340 /* scan code to virtual key maps */
341 scancode_to_vk,
342 sizeof(scancode_to_vk) / sizeof(scancode_to_vk[0]),
343 extcode0_to_vk,
344 extcode1_to_vk,
345
346 MAKELONG(0,1), /* Version 1.0 */
347
348 /* Ligatures -- English doesn't have any */
349 0,
350 0,
351 NULL
352 };
353
354 PKBDTABLES STDCALL KbdLayerDescriptor() {
355 return &keyboard_layout_table;
356 }
357