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
,
58 [KEY_BTAB
] = '\t' | KEYSYM_SHIFT
,
61 static const int curses2keycode
[CURSES_KEYS
] = {
62 [0 ... (CURSES_KEYS
- 1)] = -1,
64 [0x01b] = 1, /* Escape */
77 [0x07f] = 14, /* Backspace */
78 [KEY_BACKSPACE
] = 14, /* Backspace */
80 ['\t'] = 15, /* Tab */
93 ['\n'] = 28, /* Return */
94 ['\r'] = 28, /* Return */
95 [KEY_ENTER
] = 28, /* Return */
107 ['\''] = 40, /* Single quote */
109 ['\\'] = 43, /* Backslash */
124 [KEY_F(1)] = 59, /* Function Key 1 */
125 [KEY_F(2)] = 60, /* Function Key 2 */
126 [KEY_F(3)] = 61, /* Function Key 3 */
127 [KEY_F(4)] = 62, /* Function Key 4 */
128 [KEY_F(5)] = 63, /* Function Key 5 */
129 [KEY_F(6)] = 64, /* Function Key 6 */
130 [KEY_F(7)] = 65, /* Function Key 7 */
131 [KEY_F(8)] = 66, /* Function Key 8 */
132 [KEY_F(9)] = 67, /* Function Key 9 */
133 [KEY_F(10)] = 68, /* Function Key 10 */
134 [KEY_F(11)] = 87, /* Function Key 11 */
135 [KEY_F(12)] = 88, /* Function Key 12 */
137 [KEY_HOME
] = 71 | GREY
, /* Home */
138 [KEY_UP
] = 72 | GREY
, /* Up Arrow */
139 [KEY_PPAGE
] = 73 | GREY
, /* Page Up */
140 [KEY_LEFT
] = 75 | GREY
, /* Left Arrow */
141 [KEY_RIGHT
] = 77 | GREY
, /* Right Arrow */
142 [KEY_END
] = 79 | GREY
, /* End */
143 [KEY_DOWN
] = 80 | GREY
, /* Down Arrow */
144 [KEY_NPAGE
] = 81 | GREY
, /* Page Down */
145 [KEY_IC
] = 82 | GREY
, /* Insert */
146 [KEY_DC
] = 83 | GREY
, /* Delete */
161 [KEY_BTAB
] = 15 | SHIFT
, /* Shift + Tab */
200 [KEY_F(13)] = 59 | SHIFT
, /* Shift + Function Key 1 */
201 [KEY_F(14)] = 60 | SHIFT
, /* Shift + Function Key 2 */
202 [KEY_F(15)] = 61 | SHIFT
, /* Shift + Function Key 3 */
203 [KEY_F(16)] = 62 | SHIFT
, /* Shift + Function Key 4 */
204 [KEY_F(17)] = 63 | SHIFT
, /* Shift + Function Key 5 */
205 [KEY_F(18)] = 64 | SHIFT
, /* Shift + Function Key 6 */
206 [KEY_F(19)] = 65 | SHIFT
, /* Shift + Function Key 7 */
207 [KEY_F(20)] = 66 | SHIFT
, /* Shift + Function Key 8 */
208 [KEY_F(21)] = 67 | SHIFT
, /* Shift + Function Key 9 */
209 [KEY_F(22)] = 68 | SHIFT
, /* Shift + Function Key 10 */
210 [KEY_F(23)] = 69 | SHIFT
, /* Shift + Function Key 11 */
211 [KEY_F(24)] = 70 | SHIFT
, /* Shift + Function Key 12 */
213 ['Q' - '@'] = 16 | CNTRL
, /* Control + q */
214 ['W' - '@'] = 17 | CNTRL
, /* Control + w */
215 ['E' - '@'] = 18 | CNTRL
, /* Control + e */
216 ['R' - '@'] = 19 | CNTRL
, /* Control + r */
217 ['T' - '@'] = 20 | CNTRL
, /* Control + t */
218 ['Y' - '@'] = 21 | CNTRL
, /* Control + y */
219 ['U' - '@'] = 22 | CNTRL
, /* Control + u */
220 /* Control + i collides with Tab */
221 ['O' - '@'] = 24 | CNTRL
, /* Control + o */
222 ['P' - '@'] = 25 | CNTRL
, /* Control + p */
224 ['A' - '@'] = 30 | CNTRL
, /* Control + a */
225 ['S' - '@'] = 31 | CNTRL
, /* Control + s */
226 ['D' - '@'] = 32 | CNTRL
, /* Control + d */
227 ['F' - '@'] = 33 | CNTRL
, /* Control + f */
228 ['G' - '@'] = 34 | CNTRL
, /* Control + g */
229 ['H' - '@'] = 35 | CNTRL
, /* Control + h */
230 /* Control + j collides with Return */
231 ['K' - '@'] = 37 | CNTRL
, /* Control + k */
232 ['L' - '@'] = 38 | CNTRL
, /* Control + l */
234 ['Z' - '@'] = 44 | CNTRL
, /* Control + z */
235 ['X' - '@'] = 45 | CNTRL
, /* Control + x */
236 ['C' - '@'] = 46 | CNTRL
, /* Control + c */
237 ['V' - '@'] = 47 | CNTRL
, /* Control + v */
238 ['B' - '@'] = 48 | CNTRL
, /* Control + b */
239 ['N' - '@'] = 49 | CNTRL
, /* Control + n */
240 /* Control + m collides with the keycode for Enter */
244 static const int curses2qemu
[CURSES_KEYS
] = {
245 [0 ... (CURSES_KEYS
- 1)] = -1,
250 [0x07f] = QEMU_KEY_BACKSPACE
,
252 [KEY_DOWN
] = QEMU_KEY_DOWN
,
253 [KEY_UP
] = QEMU_KEY_UP
,
254 [KEY_LEFT
] = QEMU_KEY_LEFT
,
255 [KEY_RIGHT
] = QEMU_KEY_RIGHT
,
256 [KEY_HOME
] = QEMU_KEY_HOME
,
257 [KEY_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
259 [KEY_DC
] = QEMU_KEY_DELETE
,
260 [KEY_NPAGE
] = QEMU_KEY_PAGEDOWN
,
261 [KEY_PPAGE
] = QEMU_KEY_PAGEUP
,
263 [KEY_END
] = QEMU_KEY_END
,
267 static const name2keysym_t name2keysym
[] = {
271 { "quotedbl", 0x022 },
272 { "numbersign", 0x023 },
274 { "percent", 0x025 },
275 { "ampersand", 0x026 },
276 { "apostrophe", 0x027 },
277 { "parenleft", 0x028 },
278 { "parenright", 0x029 },
279 { "asterisk", 0x02a },
296 { "semicolon", 0x03b },
299 { "greater", 0x03e },
300 { "question", 0x03f },
328 { "bracketleft", 0x05b },
329 { "backslash", 0x05c },
330 { "bracketright", 0x05d },
331 { "asciicircum", 0x05e },
332 { "underscore", 0x05f },
360 { "braceleft", 0x07b },
362 { "braceright", 0x07d },
363 { "asciitilde", 0x07e },
365 /* Latin-1 extensions */
366 { "nobreakspace", 0x0a0 },
367 { "exclamdown", 0x0a1 },
369 { "sterling", 0x0a3 },
370 { "currency", 0x0a4 },
372 { "brokenbar", 0x0a6 },
373 { "section", 0x0a7 },
374 { "diaeresis", 0x0a8 },
375 { "copyright", 0x0a9 },
376 { "ordfeminine", 0x0aa },
377 { "guillemotleft", 0x0ab },
378 { "notsign", 0x0ac },
380 { "registered", 0x0ae },
383 { "plusminus", 0x0b1 },
384 { "twosuperior", 0x0b2 },
385 { "threesuperior", 0x0b3 },
388 { "paragraph", 0x0b6 },
389 { "periodcentered", 0x0b7 },
390 { "cedilla", 0x0b8 },
391 { "onesuperior", 0x0b9 },
392 { "masculine", 0x0ba },
393 { "guillemotright", 0x0bb },
394 { "onequarter", 0x0bc },
395 { "onehalf", 0x0bd },
396 { "threequarters", 0x0be },
397 { "questiondown", 0x0bf },
400 { "Acircumflex", 0x0c2 },
402 { "Adiaeresis", 0x0c4 },
405 { "Ccedilla", 0x0c7 },
408 { "Ecircumflex", 0x0ca },
409 { "Ediaeresis", 0x0cb },
412 { "Icircumflex", 0x0ce },
413 { "Idiaeresis", 0x0cf },
419 { "Ocircumflex", 0x0d4 },
421 { "Odiaeresis", 0x0d6 },
422 { "multiply", 0x0d7 },
423 { "Ooblique", 0x0d8 },
427 { "Ucircumflex", 0x0db },
428 { "Udiaeresis", 0x0dc },
435 { "acircumflex", 0x0e2 },
437 { "adiaeresis", 0x0e4 },
440 { "ccedilla", 0x0e7 },
443 { "ecircumflex", 0x0ea },
444 { "ediaeresis", 0x0eb },
447 { "icircumflex", 0x0ee },
448 { "idiaeresis", 0x0ef },
453 { "ocircumflex", 0x0f4 },
455 { "odiaeresis", 0x0f6 },
456 { "division", 0x0f7 },
458 { "ooblique", 0x0f8 },
461 { "ucircumflex", 0x0fb },
462 { "udiaeresis", 0x0fc },
465 { "ydiaeresis", 0x0ff },
468 { "BackSpace", KEY_BACKSPACE
},
470 { "Return", KEY_ENTER
},
471 { "Right", KEY_RIGHT
},
472 { "Left", KEY_LEFT
},
474 { "Down", KEY_DOWN
},
475 { "Page_Down", KEY_NPAGE
},
476 { "Page_Up", KEY_PPAGE
},
477 { "Insert", KEY_IC
},
478 { "Delete", KEY_DC
},
479 { "Home", KEY_HOME
},
490 { "F10", KEY_F(10) },
491 { "F11", KEY_F(11) },
492 { "F12", KEY_F(12) },
493 { "F13", KEY_F(13) },
494 { "F14", KEY_F(14) },
495 { "F15", KEY_F(15) },
496 { "F16", KEY_F(16) },
497 { "F17", KEY_F(17) },
498 { "F18", KEY_F(18) },
499 { "F19", KEY_F(19) },
500 { "F20", KEY_F(20) },
501 { "F21", KEY_F(21) },
502 { "F22", KEY_F(22) },
503 { "F23", KEY_F(23) },
504 { "F24", KEY_F(24) },