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