2 * Keycode and keysyms conversion tables for curses
4 * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #define KEY_RELEASE 0x80
31 #define GREY_CODE 0xe0
32 #define GREY SCANCODE_GREY
33 #define SHIFT_CODE 0x2a
34 #define SHIFT SCANCODE_SHIFT
35 #define CNTRL_CODE 0x1d
36 #define CNTRL SCANCODE_CTRL
38 #define ALT SCANCODE_ALT
39 #define ALTGR SCANCODE_ALTGR
41 #define KEYSYM_MASK 0x0ffffff
42 #define KEYSYM_SHIFT (SCANCODE_SHIFT << 16)
43 #define KEYSYM_CNTRL (SCANCODE_CTRL << 16)
44 #define KEYSYM_ALT (SCANCODE_ALT << 16)
45 #define KEYSYM_ALTGR (SCANCODE_ALTGR << 16)
47 /* curses won't detect a Control + Alt + 1, so use Alt + 1 */
48 #define QEMU_KEY_CONSOLE0 (2 | ALT) /* (curses2keycode['1'] | ALT) */
50 #define CURSES_KEYS KEY_MAX /* KEY_MAX defined in <curses.h> */
52 static const int curses2keysym
[CURSES_KEYS
] = {
53 [0 ... (CURSES_KEYS
- 1)] = -1,
55 [0x7f] = KEY_BACKSPACE
,
59 [KEY_BTAB
] = '\t' | KEYSYM_SHIFT
,
62 static const int curses2keycode
[CURSES_KEYS
] = {
63 [0 ... (CURSES_KEYS
- 1)] = -1,
65 [0x01b] = 1, /* Escape */
78 [0x07f] = 14, /* Backspace */
79 [KEY_BACKSPACE
] = 14, /* Backspace */
81 ['\t'] = 15, /* Tab */
94 ['\n'] = 28, /* Return */
95 ['\r'] = 28, /* Return */
96 [KEY_ENTER
] = 28, /* Return */
108 ['\''] = 40, /* Single quote */
110 ['\\'] = 43, /* Backslash */
125 [KEY_F(1)] = 59, /* Function Key 1 */
126 [KEY_F(2)] = 60, /* Function Key 2 */
127 [KEY_F(3)] = 61, /* Function Key 3 */
128 [KEY_F(4)] = 62, /* Function Key 4 */
129 [KEY_F(5)] = 63, /* Function Key 5 */
130 [KEY_F(6)] = 64, /* Function Key 6 */
131 [KEY_F(7)] = 65, /* Function Key 7 */
132 [KEY_F(8)] = 66, /* Function Key 8 */
133 [KEY_F(9)] = 67, /* Function Key 9 */
134 [KEY_F(10)] = 68, /* Function Key 10 */
135 [KEY_F(11)] = 87, /* Function Key 11 */
136 [KEY_F(12)] = 88, /* Function Key 12 */
138 [KEY_HOME
] = 71 | GREY
, /* Home */
139 [KEY_UP
] = 72 | GREY
, /* Up Arrow */
140 [KEY_PPAGE
] = 73 | GREY
, /* Page Up */
141 [KEY_LEFT
] = 75 | GREY
, /* Left Arrow */
142 [KEY_RIGHT
] = 77 | GREY
, /* Right Arrow */
143 [KEY_END
] = 79 | GREY
, /* End */
144 [KEY_DOWN
] = 80 | GREY
, /* Down Arrow */
145 [KEY_NPAGE
] = 81 | GREY
, /* Page Down */
146 [KEY_IC
] = 82 | GREY
, /* Insert */
147 [KEY_DC
] = 83 | GREY
, /* Delete */
162 [KEY_BTAB
] = 15 | SHIFT
, /* Shift + Tab */
201 [KEY_F(13)] = 59 | SHIFT
, /* Shift + Function Key 1 */
202 [KEY_F(14)] = 60 | SHIFT
, /* Shift + Function Key 2 */
203 [KEY_F(15)] = 61 | SHIFT
, /* Shift + Function Key 3 */
204 [KEY_F(16)] = 62 | SHIFT
, /* Shift + Function Key 4 */
205 [KEY_F(17)] = 63 | SHIFT
, /* Shift + Function Key 5 */
206 [KEY_F(18)] = 64 | SHIFT
, /* Shift + Function Key 6 */
207 [KEY_F(19)] = 65 | SHIFT
, /* Shift + Function Key 7 */
208 [KEY_F(20)] = 66 | SHIFT
, /* Shift + Function Key 8 */
209 [KEY_F(21)] = 67 | SHIFT
, /* Shift + Function Key 9 */
210 [KEY_F(22)] = 68 | SHIFT
, /* Shift + Function Key 10 */
211 [KEY_F(23)] = 69 | SHIFT
, /* Shift + Function Key 11 */
212 [KEY_F(24)] = 70 | SHIFT
, /* Shift + Function Key 12 */
214 ['Q' - '@'] = 16 | CNTRL
, /* Control + q */
215 ['W' - '@'] = 17 | CNTRL
, /* Control + w */
216 ['E' - '@'] = 18 | CNTRL
, /* Control + e */
217 ['R' - '@'] = 19 | CNTRL
, /* Control + r */
218 ['T' - '@'] = 20 | CNTRL
, /* Control + t */
219 ['Y' - '@'] = 21 | CNTRL
, /* Control + y */
220 ['U' - '@'] = 22 | CNTRL
, /* Control + u */
221 /* Control + i collides with Tab */
222 ['O' - '@'] = 24 | CNTRL
, /* Control + o */
223 ['P' - '@'] = 25 | CNTRL
, /* Control + p */
225 ['A' - '@'] = 30 | CNTRL
, /* Control + a */
226 ['S' - '@'] = 31 | CNTRL
, /* Control + s */
227 ['D' - '@'] = 32 | CNTRL
, /* Control + d */
228 ['F' - '@'] = 33 | CNTRL
, /* Control + f */
229 ['G' - '@'] = 34 | CNTRL
, /* Control + g */
230 ['H' - '@'] = 35 | CNTRL
, /* Control + h */
231 /* Control + j collides with Return */
232 ['K' - '@'] = 37 | CNTRL
, /* Control + k */
233 ['L' - '@'] = 38 | CNTRL
, /* Control + l */
235 ['Z' - '@'] = 44 | CNTRL
, /* Control + z */
236 ['X' - '@'] = 45 | CNTRL
, /* Control + x */
237 ['C' - '@'] = 46 | CNTRL
, /* Control + c */
238 ['V' - '@'] = 47 | CNTRL
, /* Control + v */
239 ['B' - '@'] = 48 | CNTRL
, /* Control + b */
240 ['N' - '@'] = 49 | CNTRL
, /* Control + n */
241 /* Control + m collides with the keycode for Enter */
245 static const int curses2qemu
[CURSES_KEYS
] = {
246 [0 ... (CURSES_KEYS
- 1)] = -1,
251 [0x07f] = QEMU_KEY_BACKSPACE
,
253 [KEY_DOWN
] = QEMU_KEY_DOWN
,
254 [KEY_UP
] = QEMU_KEY_UP
,
255 [KEY_LEFT
] = QEMU_KEY_LEFT
,
256 [KEY_RIGHT
] = QEMU_KEY_RIGHT
,
257 [KEY_HOME
] = QEMU_KEY_HOME
,
258 [KEY_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
260 [KEY_DC
] = QEMU_KEY_DELETE
,
261 [KEY_NPAGE
] = QEMU_KEY_PAGEDOWN
,
262 [KEY_PPAGE
] = QEMU_KEY_PAGEUP
,
264 [KEY_END
] = QEMU_KEY_END
,
268 static const name2keysym_t name2keysym
[] = {
272 { "quotedbl", 0x022 },
273 { "numbersign", 0x023 },
275 { "percent", 0x025 },
276 { "ampersand", 0x026 },
277 { "apostrophe", 0x027 },
278 { "parenleft", 0x028 },
279 { "parenright", 0x029 },
280 { "asterisk", 0x02a },
297 { "semicolon", 0x03b },
300 { "greater", 0x03e },
301 { "question", 0x03f },
329 { "bracketleft", 0x05b },
330 { "backslash", 0x05c },
331 { "bracketright", 0x05d },
332 { "asciicircum", 0x05e },
333 { "underscore", 0x05f },
361 { "braceleft", 0x07b },
363 { "braceright", 0x07d },
364 { "asciitilde", 0x07e },
366 /* Latin-1 extensions */
367 { "nobreakspace", 0x0a0 },
368 { "exclamdown", 0x0a1 },
370 { "sterling", 0x0a3 },
371 { "currency", 0x0a4 },
373 { "brokenbar", 0x0a6 },
374 { "section", 0x0a7 },
375 { "diaeresis", 0x0a8 },
376 { "copyright", 0x0a9 },
377 { "ordfeminine", 0x0aa },
378 { "guillemotleft", 0x0ab },
379 { "notsign", 0x0ac },
381 { "registered", 0x0ae },
384 { "plusminus", 0x0b1 },
385 { "twosuperior", 0x0b2 },
386 { "threesuperior", 0x0b3 },
389 { "paragraph", 0x0b6 },
390 { "periodcentered", 0x0b7 },
391 { "cedilla", 0x0b8 },
392 { "onesuperior", 0x0b9 },
393 { "masculine", 0x0ba },
394 { "guillemotright", 0x0bb },
395 { "onequarter", 0x0bc },
396 { "onehalf", 0x0bd },
397 { "threequarters", 0x0be },
398 { "questiondown", 0x0bf },
401 { "Acircumflex", 0x0c2 },
403 { "Adiaeresis", 0x0c4 },
406 { "Ccedilla", 0x0c7 },
409 { "Ecircumflex", 0x0ca },
410 { "Ediaeresis", 0x0cb },
413 { "Icircumflex", 0x0ce },
414 { "Idiaeresis", 0x0cf },
420 { "Ocircumflex", 0x0d4 },
422 { "Odiaeresis", 0x0d6 },
423 { "multiply", 0x0d7 },
424 { "Ooblique", 0x0d8 },
428 { "Ucircumflex", 0x0db },
429 { "Udiaeresis", 0x0dc },
436 { "acircumflex", 0x0e2 },
438 { "adiaeresis", 0x0e4 },
441 { "ccedilla", 0x0e7 },
444 { "ecircumflex", 0x0ea },
445 { "ediaeresis", 0x0eb },
448 { "icircumflex", 0x0ee },
449 { "idiaeresis", 0x0ef },
454 { "ocircumflex", 0x0f4 },
456 { "odiaeresis", 0x0f6 },
457 { "division", 0x0f7 },
459 { "ooblique", 0x0f8 },
462 { "ucircumflex", 0x0fb },
463 { "udiaeresis", 0x0fc },
466 { "ydiaeresis", 0x0ff },
469 { "BackSpace", KEY_BACKSPACE
},
471 { "Return", KEY_ENTER
},
472 { "Right", KEY_RIGHT
},
473 { "Left", KEY_LEFT
},
475 { "Down", KEY_DOWN
},
476 { "Page_Down", KEY_NPAGE
},
477 { "Page_Up", KEY_PPAGE
},
478 { "Insert", KEY_IC
},
479 { "Delete", KEY_DC
},
480 { "Home", KEY_HOME
},
491 { "F10", KEY_F(10) },
492 { "F11", KEY_F(11) },
493 { "F12", KEY_F(12) },
494 { "F13", KEY_F(13) },
495 { "F14", KEY_F(14) },
496 { "F15", KEY_F(15) },
497 { "F16", KEY_F(16) },
498 { "F17", KEY_F(17) },
499 { "F18", KEY_F(18) },
500 { "F19", KEY_F(19) },
501 { "F20", KEY_F(20) },
502 { "F21", KEY_F(21) },
503 { "F22", KEY_F(22) },
504 { "F23", KEY_F(23) },
505 { "F24", KEY_F(24) },