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