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
25 #ifndef QEMU_CURSES_KEYS_H
26 #define QEMU_CURSES_KEYS_H
32 #define KEY_MASK SCANCODE_KEYMASK
33 #define GREY_CODE 0xe0
34 #define GREY SCANCODE_GREY
35 #define SHIFT_CODE 0x2a
36 #define SHIFT SCANCODE_SHIFT
37 #define CNTRL_CODE 0x1d
38 #define CNTRL SCANCODE_CTRL
40 #define ALT SCANCODE_ALT
41 #define ALTGR SCANCODE_ALTGR
43 #define KEYSYM_MASK 0x0ffffff
44 #define KEYSYM_SHIFT (SCANCODE_SHIFT << 16)
45 #define KEYSYM_CNTRL (SCANCODE_CTRL << 16)
46 #define KEYSYM_ALT (SCANCODE_ALT << 16)
47 #define KEYSYM_ALTGR (SCANCODE_ALTGR << 16)
49 /* curses won't detect a Control + Alt + 1, so use Alt + 1 */
50 #define QEMU_KEY_CONSOLE0 (2 | ALT) /* (curses2keycode['1'] | ALT) */
52 #define CURSES_CHARS 0x100 /* Support latin1 only */
53 #define CURSES_KEYS KEY_MAX /* KEY_MAX defined in <curses.h> */
55 static const int _curses2keysym
[CURSES_CHARS
] = {
56 [0 ... (CURSES_CHARS
- 1)] = -1,
58 [0x7f] = KEY_BACKSPACE
,
64 static const int _curseskey2keysym
[CURSES_KEYS
] = {
65 [0 ... (CURSES_KEYS
- 1)] = -1,
67 [KEY_BTAB
] = '\t' | KEYSYM_SHIFT
,
68 [KEY_SPREVIOUS
] = KEY_PPAGE
| KEYSYM_SHIFT
,
69 [KEY_SNEXT
] = KEY_NPAGE
| KEYSYM_SHIFT
,
72 static const int _curses2keycode
[CURSES_CHARS
] = {
73 [0 ... (CURSES_CHARS
- 1)] = -1,
75 [0x01b] = 1, /* Escape */
88 [0x07f] = 14, /* Backspace */
90 ['\t'] = 15, /* Tab */
103 ['\n'] = 28, /* Return */
104 ['\r'] = 28, /* Return */
116 ['\''] = 40, /* Single quote */
118 ['\\'] = 43, /* Backslash */
184 ['Q' - '@'] = 16 | CNTRL
, /* Control + q */
185 ['W' - '@'] = 17 | CNTRL
, /* Control + w */
186 ['E' - '@'] = 18 | CNTRL
, /* Control + e */
187 ['R' - '@'] = 19 | CNTRL
, /* Control + r */
188 ['T' - '@'] = 20 | CNTRL
, /* Control + t */
189 ['Y' - '@'] = 21 | CNTRL
, /* Control + y */
190 ['U' - '@'] = 22 | CNTRL
, /* Control + u */
191 /* Control + i collides with Tab */
192 ['O' - '@'] = 24 | CNTRL
, /* Control + o */
193 ['P' - '@'] = 25 | CNTRL
, /* Control + p */
195 ['A' - '@'] = 30 | CNTRL
, /* Control + a */
196 ['S' - '@'] = 31 | CNTRL
, /* Control + s */
197 ['D' - '@'] = 32 | CNTRL
, /* Control + d */
198 ['F' - '@'] = 33 | CNTRL
, /* Control + f */
199 ['G' - '@'] = 34 | CNTRL
, /* Control + g */
200 ['H' - '@'] = 35 | CNTRL
, /* Control + h */
201 /* Control + j collides with Return */
202 ['K' - '@'] = 37 | CNTRL
, /* Control + k */
203 ['L' - '@'] = 38 | CNTRL
, /* Control + l */
205 ['Z' - '@'] = 44 | CNTRL
, /* Control + z */
206 ['X' - '@'] = 45 | CNTRL
, /* Control + x */
207 ['C' - '@'] = 46 | CNTRL
, /* Control + c */
208 ['V' - '@'] = 47 | CNTRL
, /* Control + v */
209 ['B' - '@'] = 48 | CNTRL
, /* Control + b */
210 ['N' - '@'] = 49 | CNTRL
, /* Control + n */
211 /* Control + m collides with the keycode for Enter */
213 ['@' - '@'] = 3 | CNTRL
, /* Control + @ */
214 /* Control + [ collides with the keycode for Escape */
215 ['\\' - '@'] = 43 | CNTRL
, /* Control + Backslash */
216 [']' - '@'] = 27 | CNTRL
, /* Control + ] */
217 ['^' - '@'] = 7 | CNTRL
, /* Control + ^ */
218 ['_' - '@'] = 12 | CNTRL
, /* Control + Underscore */
221 static const int _curseskey2keycode
[CURSES_KEYS
] = {
222 [0 ... (CURSES_KEYS
- 1)] = -1,
224 [KEY_BACKSPACE
] = 14, /* Backspace */
226 [KEY_ENTER
] = 28, /* Return */
228 [KEY_F(1)] = 59, /* Function Key 1 */
229 [KEY_F(2)] = 60, /* Function Key 2 */
230 [KEY_F(3)] = 61, /* Function Key 3 */
231 [KEY_F(4)] = 62, /* Function Key 4 */
232 [KEY_F(5)] = 63, /* Function Key 5 */
233 [KEY_F(6)] = 64, /* Function Key 6 */
234 [KEY_F(7)] = 65, /* Function Key 7 */
235 [KEY_F(8)] = 66, /* Function Key 8 */
236 [KEY_F(9)] = 67, /* Function Key 9 */
237 [KEY_F(10)] = 68, /* Function Key 10 */
238 [KEY_F(11)] = 87, /* Function Key 11 */
239 [KEY_F(12)] = 88, /* Function Key 12 */
241 [KEY_HOME
] = 71 | GREY
, /* Home */
242 [KEY_UP
] = 72 | GREY
, /* Up Arrow */
243 [KEY_PPAGE
] = 73 | GREY
, /* Page Up */
244 [KEY_LEFT
] = 75 | GREY
, /* Left Arrow */
245 [KEY_RIGHT
] = 77 | GREY
, /* Right Arrow */
246 [KEY_END
] = 79 | GREY
, /* End */
247 [KEY_DOWN
] = 80 | GREY
, /* Down Arrow */
248 [KEY_NPAGE
] = 81 | GREY
, /* Page Down */
249 [KEY_IC
] = 82 | GREY
, /* Insert */
250 [KEY_DC
] = 83 | GREY
, /* Delete */
252 [KEY_SPREVIOUS
] = 73 | GREY
| SHIFT
, /* Shift + Page Up */
253 [KEY_SNEXT
] = 81 | GREY
| SHIFT
, /* Shift + Page Down */
255 [KEY_BTAB
] = 15 | SHIFT
, /* Shift + Tab */
257 [KEY_F(13)] = 59 | SHIFT
, /* Shift + Function Key 1 */
258 [KEY_F(14)] = 60 | SHIFT
, /* Shift + Function Key 2 */
259 [KEY_F(15)] = 61 | SHIFT
, /* Shift + Function Key 3 */
260 [KEY_F(16)] = 62 | SHIFT
, /* Shift + Function Key 4 */
261 [KEY_F(17)] = 63 | SHIFT
, /* Shift + Function Key 5 */
262 [KEY_F(18)] = 64 | SHIFT
, /* Shift + Function Key 6 */
263 [KEY_F(19)] = 65 | SHIFT
, /* Shift + Function Key 7 */
264 [KEY_F(20)] = 66 | SHIFT
, /* Shift + Function Key 8 */
265 [KEY_F(21)] = 67 | SHIFT
, /* Shift + Function Key 9 */
266 [KEY_F(22)] = 68 | SHIFT
, /* Shift + Function Key 10 */
267 [KEY_F(23)] = 69 | SHIFT
, /* Shift + Function Key 11 */
268 [KEY_F(24)] = 70 | SHIFT
, /* Shift + Function Key 12 */
271 static const int _curses2qemu
[CURSES_CHARS
] = {
272 [0 ... (CURSES_CHARS
- 1)] = -1,
277 [0x07f] = QEMU_KEY_BACKSPACE
,
280 static const int _curseskey2qemu
[CURSES_KEYS
] = {
281 [0 ... (CURSES_KEYS
- 1)] = -1,
283 [KEY_DOWN
] = QEMU_KEY_DOWN
,
284 [KEY_UP
] = QEMU_KEY_UP
,
285 [KEY_LEFT
] = QEMU_KEY_LEFT
,
286 [KEY_RIGHT
] = QEMU_KEY_RIGHT
,
287 [KEY_HOME
] = QEMU_KEY_HOME
,
288 [KEY_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
290 [KEY_DC
] = QEMU_KEY_DELETE
,
291 [KEY_NPAGE
] = QEMU_KEY_PAGEDOWN
,
292 [KEY_PPAGE
] = QEMU_KEY_PAGEUP
,
294 [KEY_END
] = QEMU_KEY_END
,
298 static const name2keysym_t name2keysym
[] = {
302 { "quotedbl", 0x022 },
303 { "numbersign", 0x023 },
305 { "percent", 0x025 },
306 { "ampersand", 0x026 },
307 { "apostrophe", 0x027 },
308 { "parenleft", 0x028 },
309 { "parenright", 0x029 },
310 { "asterisk", 0x02a },
327 { "semicolon", 0x03b },
330 { "greater", 0x03e },
331 { "question", 0x03f },
359 { "bracketleft", 0x05b },
360 { "backslash", 0x05c },
361 { "bracketright", 0x05d },
362 { "asciicircum", 0x05e },
363 { "underscore", 0x05f },
391 { "braceleft", 0x07b },
393 { "braceright", 0x07d },
394 { "asciitilde", 0x07e },
396 /* Latin-1 extensions */
397 { "nobreakspace", 0x0a0 },
398 { "exclamdown", 0x0a1 },
400 { "sterling", 0x0a3 },
401 { "currency", 0x0a4 },
403 { "brokenbar", 0x0a6 },
404 { "section", 0x0a7 },
405 { "diaeresis", 0x0a8 },
406 { "copyright", 0x0a9 },
407 { "ordfeminine", 0x0aa },
408 { "guillemotleft", 0x0ab },
409 { "notsign", 0x0ac },
411 { "registered", 0x0ae },
414 { "plusminus", 0x0b1 },
415 { "twosuperior", 0x0b2 },
416 { "threesuperior", 0x0b3 },
419 { "paragraph", 0x0b6 },
420 { "periodcentered", 0x0b7 },
421 { "cedilla", 0x0b8 },
422 { "onesuperior", 0x0b9 },
423 { "masculine", 0x0ba },
424 { "guillemotright", 0x0bb },
425 { "onequarter", 0x0bc },
426 { "onehalf", 0x0bd },
427 { "threequarters", 0x0be },
428 { "questiondown", 0x0bf },
431 { "Acircumflex", 0x0c2 },
433 { "Adiaeresis", 0x0c4 },
436 { "Ccedilla", 0x0c7 },
439 { "Ecircumflex", 0x0ca },
440 { "Ediaeresis", 0x0cb },
443 { "Icircumflex", 0x0ce },
444 { "Idiaeresis", 0x0cf },
450 { "Ocircumflex", 0x0d4 },
452 { "Odiaeresis", 0x0d6 },
453 { "multiply", 0x0d7 },
454 { "Ooblique", 0x0d8 },
458 { "Ucircumflex", 0x0db },
459 { "Udiaeresis", 0x0dc },
466 { "acircumflex", 0x0e2 },
468 { "adiaeresis", 0x0e4 },
471 { "ccedilla", 0x0e7 },
474 { "ecircumflex", 0x0ea },
475 { "ediaeresis", 0x0eb },
478 { "icircumflex", 0x0ee },
479 { "idiaeresis", 0x0ef },
484 { "ocircumflex", 0x0f4 },
486 { "odiaeresis", 0x0f6 },
487 { "division", 0x0f7 },
489 { "ooblique", 0x0f8 },
492 { "ucircumflex", 0x0fb },
493 { "udiaeresis", 0x0fc },
496 { "ydiaeresis", 0x0ff },
499 { "BackSpace", KEY_BACKSPACE
},
501 { "Return", KEY_ENTER
},
502 { "Right", KEY_RIGHT
},
503 { "Left", KEY_LEFT
},
505 { "Down", KEY_DOWN
},
506 { "Next", KEY_NPAGE
},
507 { "Page_Down", KEY_NPAGE
},
508 { "Prior", KEY_PPAGE
},
509 { "Page_Up", KEY_PPAGE
},
510 { "Insert", KEY_IC
},
511 { "Delete", KEY_DC
},
512 { "Home", KEY_HOME
},
523 { "F10", KEY_F(10) },
524 { "F11", KEY_F(11) },
525 { "F12", KEY_F(12) },
526 { "F13", KEY_F(13) },
527 { "F14", KEY_F(14) },
528 { "F15", KEY_F(15) },
529 { "F16", KEY_F(16) },
530 { "F17", KEY_F(17) },
531 { "F18", KEY_F(18) },
532 { "F19", KEY_F(19) },
533 { "F20", KEY_F(20) },
534 { "F21", KEY_F(21) },
535 { "F22", KEY_F(22) },
536 { "F23", KEY_F(23) },
537 { "F24", KEY_F(24) },