xref: /openbmc/qemu/ui/curses_keys.h (revision 05caa062)
1 /*
2  * Keycode and keysyms conversion tables for curses
3  *
4  * Copyright (c) 2005 Andrzej Zaborowski  <balrog@zabor.org>
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  */
24 
25 #ifndef QEMU_CURSES_KEYS_H
26 #define QEMU_CURSES_KEYS_H
27 
28 #include <curses.h>
29 #include "keymaps.h"
30 
31 
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
39 #define ALT_CODE            0x38
40 #define ALT                 SCANCODE_ALT
41 #define ALTGR               SCANCODE_ALTGR
42 
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)
48 
49 /* curses won't detect a Control + Alt + 1, so use Alt + 1 */
50 #define QEMU_KEY_CONSOLE0   (2 | ALT)   /* (curses2keycode['1'] | ALT) */
51 
52 #define CURSES_CHARS        0x100       /* Support latin1 only */
53 #define CURSES_KEYS         KEY_MAX     /* KEY_MAX defined in <curses.h> */
54 
55 static const int _curses2keysym[CURSES_CHARS] = {
56     [0 ... (CURSES_CHARS - 1)] = -1,
57 
58     [0x7f] = KEY_BACKSPACE,
59     ['\r'] = KEY_ENTER,
60     ['\n'] = KEY_ENTER,
61     [27] = 27,
62 };
63 
64 static const int _curseskey2keysym[CURSES_KEYS] = {
65     [0 ... (CURSES_KEYS - 1)] = -1,
66 
67     [KEY_BTAB] = '\t' | KEYSYM_SHIFT,
68     [KEY_SPREVIOUS] = KEY_PPAGE | KEYSYM_SHIFT,
69     [KEY_SNEXT] = KEY_NPAGE | KEYSYM_SHIFT,
70 };
71 
72 static const int _curses2keycode[CURSES_CHARS] = {
73     [0 ... (CURSES_CHARS - 1)] = -1,
74 
75     [0x01b] = 1, /* Escape */
76     ['1'] = 2,
77     ['2'] = 3,
78     ['3'] = 4,
79     ['4'] = 5,
80     ['5'] = 6,
81     ['6'] = 7,
82     ['7'] = 8,
83     ['8'] = 9,
84     ['9'] = 10,
85     ['0'] = 11,
86     ['-'] = 12,
87     ['='] = 13,
88     [0x07f] = 14, /* Backspace */
89 
90     ['\t'] = 15, /* Tab */
91     ['q'] = 16,
92     ['w'] = 17,
93     ['e'] = 18,
94     ['r'] = 19,
95     ['t'] = 20,
96     ['y'] = 21,
97     ['u'] = 22,
98     ['i'] = 23,
99     ['o'] = 24,
100     ['p'] = 25,
101     ['['] = 26,
102     [']'] = 27,
103     ['\n'] = 28, /* Return */
104     ['\r'] = 28, /* Return */
105 
106     ['a'] = 30,
107     ['s'] = 31,
108     ['d'] = 32,
109     ['f'] = 33,
110     ['g'] = 34,
111     ['h'] = 35,
112     ['j'] = 36,
113     ['k'] = 37,
114     ['l'] = 38,
115     [';'] = 39,
116     ['\''] = 40, /* Single quote */
117     ['`'] = 41,
118     ['\\'] = 43, /* Backslash */
119 
120     ['z'] = 44,
121     ['x'] = 45,
122     ['c'] = 46,
123     ['v'] = 47,
124     ['b'] = 48,
125     ['n'] = 49,
126     ['m'] = 50,
127     [','] = 51,
128     ['.'] = 52,
129     ['/'] = 53,
130 
131     [' '] = 57,
132 
133     ['!'] = 2 | SHIFT,
134     ['@'] = 3 | SHIFT,
135     ['#'] = 4 | SHIFT,
136     ['$'] = 5 | SHIFT,
137     ['%'] = 6 | SHIFT,
138     ['^'] = 7 | SHIFT,
139     ['&'] = 8 | SHIFT,
140     ['*'] = 9 | SHIFT,
141     ['('] = 10 | SHIFT,
142     [')'] = 11 | SHIFT,
143     ['_'] = 12 | SHIFT,
144     ['+'] = 13 | SHIFT,
145 
146     ['Q'] = 16 | SHIFT,
147     ['W'] = 17 | SHIFT,
148     ['E'] = 18 | SHIFT,
149     ['R'] = 19 | SHIFT,
150     ['T'] = 20 | SHIFT,
151     ['Y'] = 21 | SHIFT,
152     ['U'] = 22 | SHIFT,
153     ['I'] = 23 | SHIFT,
154     ['O'] = 24 | SHIFT,
155     ['P'] = 25 | SHIFT,
156     ['{'] = 26 | SHIFT,
157     ['}'] = 27 | SHIFT,
158 
159     ['A'] = 30 | SHIFT,
160     ['S'] = 31 | SHIFT,
161     ['D'] = 32 | SHIFT,
162     ['F'] = 33 | SHIFT,
163     ['G'] = 34 | SHIFT,
164     ['H'] = 35 | SHIFT,
165     ['J'] = 36 | SHIFT,
166     ['K'] = 37 | SHIFT,
167     ['L'] = 38 | SHIFT,
168     [':'] = 39 | SHIFT,
169     ['"'] = 40 | SHIFT,
170     ['~'] = 41 | SHIFT,
171     ['|'] = 43 | SHIFT,
172 
173     ['Z'] = 44 | SHIFT,
174     ['X'] = 45 | SHIFT,
175     ['C'] = 46 | SHIFT,
176     ['V'] = 47 | SHIFT,
177     ['B'] = 48 | SHIFT,
178     ['N'] = 49 | SHIFT,
179     ['M'] = 50 | SHIFT,
180     ['<'] = 51 | SHIFT,
181     ['>'] = 52 | SHIFT,
182     ['?'] = 53 | SHIFT,
183 
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 */
194 
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 */
204 
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 */
212 
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 */
219 };
220 
221 static const int _curseskey2keycode[CURSES_KEYS] = {
222     [0 ... (CURSES_KEYS - 1)] = -1,
223 
224     [KEY_BACKSPACE] = 14, /* Backspace */
225 
226     [KEY_ENTER] = 28, /* Return */
227 
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 */
240 
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 */
251 
252     [KEY_SPREVIOUS] = 73 | GREY | SHIFT, /* Shift + Page Up */
253     [KEY_SNEXT] = 81 | GREY | SHIFT, /* Shift + Page Down */
254 
255     [KEY_BTAB] = 15 | SHIFT, /* Shift + Tab */
256 
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 */
269 };
270 
271 static const int _curses2qemu[CURSES_CHARS] = {
272     [0 ... (CURSES_CHARS - 1)] = -1,
273 
274     ['\n'] = '\n',
275     ['\r'] = '\n',
276 
277     [0x07f] = QEMU_KEY_BACKSPACE,
278 };
279 
280 static const int _curseskey2qemu[CURSES_KEYS] = {
281     [0 ... (CURSES_KEYS - 1)] = -1,
282 
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,
289 
290     [KEY_DC] = QEMU_KEY_DELETE,
291     [KEY_NPAGE] = QEMU_KEY_PAGEDOWN,
292     [KEY_PPAGE] = QEMU_KEY_PAGEUP,
293     [KEY_ENTER] = '\n',
294     [KEY_END] = QEMU_KEY_END,
295 
296 };
297 
298 static const name2keysym_t name2keysym[] = {
299     /* Plain ASCII */
300     { "space", 0x020 },
301     { "exclam", 0x021 },
302     { "quotedbl", 0x022 },
303     { "numbersign", 0x023 },
304     { "dollar", 0x024 },
305     { "percent", 0x025 },
306     { "ampersand", 0x026 },
307     { "apostrophe", 0x027 },
308     { "parenleft", 0x028 },
309     { "parenright", 0x029 },
310     { "asterisk", 0x02a },
311     { "plus", 0x02b },
312     { "comma", 0x02c },
313     { "minus", 0x02d },
314     { "period", 0x02e },
315     { "slash", 0x02f },
316     { "0", 0x030 },
317     { "1", 0x031 },
318     { "2", 0x032 },
319     { "3", 0x033 },
320     { "4", 0x034 },
321     { "5", 0x035 },
322     { "6", 0x036 },
323     { "7", 0x037 },
324     { "8", 0x038 },
325     { "9", 0x039 },
326     { "colon", 0x03a },
327     { "semicolon", 0x03b },
328     { "less", 0x03c },
329     { "equal", 0x03d },
330     { "greater", 0x03e },
331     { "question", 0x03f },
332     { "at", 0x040 },
333     { "A", 0x041 },
334     { "B", 0x042 },
335     { "C", 0x043 },
336     { "D", 0x044 },
337     { "E", 0x045 },
338     { "F", 0x046 },
339     { "G", 0x047 },
340     { "H", 0x048 },
341     { "I", 0x049 },
342     { "J", 0x04a },
343     { "K", 0x04b },
344     { "L", 0x04c },
345     { "M", 0x04d },
346     { "N", 0x04e },
347     { "O", 0x04f },
348     { "P", 0x050 },
349     { "Q", 0x051 },
350     { "R", 0x052 },
351     { "S", 0x053 },
352     { "T", 0x054 },
353     { "U", 0x055 },
354     { "V", 0x056 },
355     { "W", 0x057 },
356     { "X", 0x058 },
357     { "Y", 0x059 },
358     { "Z", 0x05a },
359     { "bracketleft", 0x05b },
360     { "backslash", 0x05c },
361     { "bracketright", 0x05d },
362     { "asciicircum", 0x05e },
363     { "underscore", 0x05f },
364     { "grave", 0x060 },
365     { "a", 0x061 },
366     { "b", 0x062 },
367     { "c", 0x063 },
368     { "d", 0x064 },
369     { "e", 0x065 },
370     { "f", 0x066 },
371     { "g", 0x067 },
372     { "h", 0x068 },
373     { "i", 0x069 },
374     { "j", 0x06a },
375     { "k", 0x06b },
376     { "l", 0x06c },
377     { "m", 0x06d },
378     { "n", 0x06e },
379     { "o", 0x06f },
380     { "p", 0x070 },
381     { "q", 0x071 },
382     { "r", 0x072 },
383     { "s", 0x073 },
384     { "t", 0x074 },
385     { "u", 0x075 },
386     { "v", 0x076 },
387     { "w", 0x077 },
388     { "x", 0x078 },
389     { "y", 0x079 },
390     { "z", 0x07a },
391     { "braceleft", 0x07b },
392     { "bar", 0x07c },
393     { "braceright", 0x07d },
394     { "asciitilde", 0x07e },
395 
396     /* Latin-1 extensions */
397     { "nobreakspace", 0x0a0 },
398     { "exclamdown", 0x0a1 },
399     { "cent", 0x0a2 },
400     { "sterling", 0x0a3 },
401     { "currency", 0x0a4 },
402     { "yen", 0x0a5 },
403     { "brokenbar", 0x0a6 },
404     { "section", 0x0a7 },
405     { "diaeresis", 0x0a8 },
406     { "copyright", 0x0a9 },
407     { "ordfeminine", 0x0aa },
408     { "guillemotleft", 0x0ab },
409     { "notsign", 0x0ac },
410     { "hyphen", 0x0ad },
411     { "registered", 0x0ae },
412     { "macron", 0x0af },
413     { "degree", 0x0b0 },
414     { "plusminus", 0x0b1 },
415     { "twosuperior", 0x0b2 },
416     { "threesuperior", 0x0b3 },
417     { "acute", 0x0b4 },
418     { "mu", 0x0b5 },
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 },
429     { "Agrave", 0x0c0 },
430     { "Aacute", 0x0c1 },
431     { "Acircumflex", 0x0c2 },
432     { "Atilde", 0x0c3 },
433     { "Adiaeresis", 0x0c4 },
434     { "Aring", 0x0c5 },
435     { "AE", 0x0c6 },
436     { "Ccedilla", 0x0c7 },
437     { "Egrave", 0x0c8 },
438     { "Eacute", 0x0c9 },
439     { "Ecircumflex", 0x0ca },
440     { "Ediaeresis", 0x0cb },
441     { "Igrave", 0x0cc },
442     { "Iacute", 0x0cd },
443     { "Icircumflex", 0x0ce },
444     { "Idiaeresis", 0x0cf },
445     { "ETH", 0x0d0 },
446     { "Eth", 0x0d0 },
447     { "Ntilde", 0x0d1 },
448     { "Ograve", 0x0d2 },
449     { "Oacute", 0x0d3 },
450     { "Ocircumflex", 0x0d4 },
451     { "Otilde", 0x0d5 },
452     { "Odiaeresis", 0x0d6 },
453     { "multiply", 0x0d7 },
454     { "Ooblique", 0x0d8 },
455     { "Oslash", 0x0d8 },
456     { "Ugrave", 0x0d9 },
457     { "Uacute", 0x0da },
458     { "Ucircumflex", 0x0db },
459     { "Udiaeresis", 0x0dc },
460     { "Yacute", 0x0dd },
461     { "THORN", 0x0de },
462     { "Thorn", 0x0de },
463     { "ssharp", 0x0df },
464     { "agrave", 0x0e0 },
465     { "aacute", 0x0e1 },
466     { "acircumflex", 0x0e2 },
467     { "atilde", 0x0e3 },
468     { "adiaeresis", 0x0e4 },
469     { "aring", 0x0e5 },
470     { "ae", 0x0e6 },
471     { "ccedilla", 0x0e7 },
472     { "egrave", 0x0e8 },
473     { "eacute", 0x0e9 },
474     { "ecircumflex", 0x0ea },
475     { "ediaeresis", 0x0eb },
476     { "igrave", 0x0ec },
477     { "iacute", 0x0ed },
478     { "icircumflex", 0x0ee },
479     { "idiaeresis", 0x0ef },
480     { "eth", 0x0f0 },
481     { "ntilde", 0x0f1 },
482     { "ograve", 0x0f2 },
483     { "oacute", 0x0f3 },
484     { "ocircumflex", 0x0f4 },
485     { "otilde", 0x0f5 },
486     { "odiaeresis", 0x0f6 },
487     { "division", 0x0f7 },
488     { "oslash", 0x0f8 },
489     { "ooblique", 0x0f8 },
490     { "ugrave", 0x0f9 },
491     { "uacute", 0x0fa },
492     { "ucircumflex", 0x0fb },
493     { "udiaeresis", 0x0fc },
494     { "yacute", 0x0fd },
495     { "thorn", 0x0fe },
496     { "ydiaeresis", 0x0ff },
497 
498     /* Special keys */
499     { "BackSpace", KEY_BACKSPACE },
500     { "Tab", '\t' },
501     { "Return", KEY_ENTER },
502     { "Right", KEY_RIGHT },
503     { "Left", KEY_LEFT },
504     { "Up", KEY_UP },
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 },
513     { "End", KEY_END },
514     { "F1", KEY_F(1) },
515     { "F2", KEY_F(2) },
516     { "F3", KEY_F(3) },
517     { "F4", KEY_F(4) },
518     { "F5", KEY_F(5) },
519     { "F6", KEY_F(6) },
520     { "F7", KEY_F(7) },
521     { "F8", KEY_F(8) },
522     { "F9", KEY_F(9) },
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) },
538     { "Escape", 27 },
539 
540     { NULL, 0 },
541 };
542 
543 #endif
544