Statistics
| Branch: | Revision:

root / ui / curses_keys.h @ d03703c8

History | View | Annotate | Download (13.6 kB)

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
#include <curses.h>
26
#include "keymaps.h"
27

    
28

    
29
#define KEY_RELEASE         0x80
30
#define KEY_MASK            0x7f
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
37
#define ALT_CODE            0x38
38
#define ALT                 SCANCODE_ALT
39
#define ALTGR               SCANCODE_ALTGR
40

    
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)
46

    
47
/* curses won't detect a Control + Alt + 1, so use Alt + 1 */
48
#define QEMU_KEY_CONSOLE0   (2 | ALT)   /* (curses2keycode['1'] | ALT) */
49

    
50
#define CURSES_KEYS         KEY_MAX     /* KEY_MAX defined in <curses.h> */
51

    
52
static const int curses2keysym[CURSES_KEYS] = {
53
    [0 ... (CURSES_KEYS - 1)] = -1,
54

    
55
    [0x7f] = KEY_BACKSPACE,
56
    ['\r'] = KEY_ENTER,
57
    ['\n'] = KEY_ENTER,
58
    [27] = 27,
59
    [KEY_BTAB] = '\t' | KEYSYM_SHIFT,
60
};
61

    
62
static const int curses2keycode[CURSES_KEYS] = {
63
    [0 ... (CURSES_KEYS - 1)] = -1,
64

    
65
    [0x01b] = 1, /* Escape */
66
    ['1'] = 2,
67
    ['2'] = 3,
68
    ['3'] = 4,
69
    ['4'] = 5,
70
    ['5'] = 6,
71
    ['6'] = 7,
72
    ['7'] = 8,
73
    ['8'] = 9,
74
    ['9'] = 10,
75
    ['0'] = 11,
76
    ['-'] = 12,
77
    ['='] = 13,
78
    [0x07f] = 14, /* Backspace */
79
    [KEY_BACKSPACE] = 14, /* Backspace */
80

    
81
    ['\t'] = 15, /* Tab */
82
    ['q'] = 16,
83
    ['w'] = 17,
84
    ['e'] = 18,
85
    ['r'] = 19,
86
    ['t'] = 20,
87
    ['y'] = 21,
88
    ['u'] = 22,
89
    ['i'] = 23,
90
    ['o'] = 24,
91
    ['p'] = 25,
92
    ['['] = 26,
93
    [']'] = 27,
94
    ['\n'] = 28, /* Return */
95
    ['\r'] = 28, /* Return */
96
    [KEY_ENTER] = 28, /* Return */
97

    
98
    ['a'] = 30,
99
    ['s'] = 31,
100
    ['d'] = 32,
101
    ['f'] = 33,
102
    ['g'] = 34,
103
    ['h'] = 35,
104
    ['j'] = 36,
105
    ['k'] = 37,
106
    ['l'] = 38,
107
    [';'] = 39,
108
    ['\''] = 40, /* Single quote */
109
    ['`'] = 41,
110
    ['\\'] = 43, /* Backslash */
111

    
112
    ['z'] = 44,
113
    ['x'] = 45,
114
    ['c'] = 46,
115
    ['v'] = 47,
116
    ['b'] = 48,
117
    ['n'] = 49,
118
    ['m'] = 50,
119
    [','] = 51,
120
    ['.'] = 52,
121
    ['/'] = 53,
122

    
123
    [' '] = 57,
124

    
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 */
137

    
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 */
148

    
149
    ['!'] = 2 | SHIFT,
150
    ['@'] = 3 | SHIFT,
151
    ['#'] = 4 | SHIFT,
152
    ['$'] = 5 | SHIFT,
153
    ['%'] = 6 | SHIFT,
154
    ['^'] = 7 | SHIFT,
155
    ['&'] = 8 | SHIFT,
156
    ['*'] = 9 | SHIFT,
157
    ['('] = 10 | SHIFT,
158
    [')'] = 11 | SHIFT,
159
    ['_'] = 12 | SHIFT,
160
    ['+'] = 13 | SHIFT,
161

    
162
    [KEY_BTAB] = 15 | SHIFT, /* Shift + Tab */
163
    ['Q'] = 16 | SHIFT,
164
    ['W'] = 17 | SHIFT,
165
    ['E'] = 18 | SHIFT,
166
    ['R'] = 19 | SHIFT,
167
    ['T'] = 20 | SHIFT,
168
    ['Y'] = 21 | SHIFT,
169
    ['U'] = 22 | SHIFT,
170
    ['I'] = 23 | SHIFT,
171
    ['O'] = 24 | SHIFT,
172
    ['P'] = 25 | SHIFT,
173
    ['{'] = 26 | SHIFT,
174
    ['}'] = 27 | SHIFT,
175

    
176
    ['A'] = 30 | SHIFT,
177
    ['S'] = 31 | SHIFT,
178
    ['D'] = 32 | SHIFT,
179
    ['F'] = 33 | SHIFT,
180
    ['G'] = 34 | SHIFT,
181
    ['H'] = 35 | SHIFT,
182
    ['J'] = 36 | SHIFT,
183
    ['K'] = 37 | SHIFT,
184
    ['L'] = 38 | SHIFT,
185
    [':'] = 39 | SHIFT,
186
    ['"'] = 40 | SHIFT,
187
    ['~'] = 41 | SHIFT,
188
    ['|'] = 43 | SHIFT,
189

    
190
    ['Z'] = 44 | SHIFT,
191
    ['X'] = 45 | SHIFT,
192
    ['C'] = 46 | SHIFT,
193
    ['V'] = 47 | SHIFT,
194
    ['B'] = 48 | SHIFT,
195
    ['N'] = 49 | SHIFT,
196
    ['M'] = 50 | SHIFT,
197
    ['<'] = 51 | SHIFT,
198
    ['>'] = 52 | SHIFT,
199
    ['?'] = 53 | SHIFT,
200

    
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 */
213

    
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 */
224

    
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 */
234

    
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 */
242

    
243
};
244

    
245
static const int curses2qemu[CURSES_KEYS] = {
246
    [0 ... (CURSES_KEYS - 1)] = -1,
247

    
248
    ['\n'] = '\n',
249
    ['\r'] = '\n',
250

    
251
    [0x07f] = QEMU_KEY_BACKSPACE,
252

    
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,
259

    
260
    [KEY_DC] = QEMU_KEY_DELETE,
261
    [KEY_NPAGE] = QEMU_KEY_PAGEDOWN,
262
    [KEY_PPAGE] = QEMU_KEY_PAGEUP,
263
    [KEY_ENTER] = '\n',
264
    [KEY_END] = QEMU_KEY_END,
265

    
266
};
267

    
268
static const name2keysym_t name2keysym[] = {
269
    /* Plain ASCII */
270
    { "space", 0x020 },
271
    { "exclam", 0x021 },
272
    { "quotedbl", 0x022 },
273
    { "numbersign", 0x023 },
274
    { "dollar", 0x024 },
275
    { "percent", 0x025 },
276
    { "ampersand", 0x026 },
277
    { "apostrophe", 0x027 },
278
    { "parenleft", 0x028 },
279
    { "parenright", 0x029 },
280
    { "asterisk", 0x02a },
281
    { "plus", 0x02b },
282
    { "comma", 0x02c },
283
    { "minus", 0x02d },
284
    { "period", 0x02e },
285
    { "slash", 0x02f },
286
    { "0", 0x030 },
287
    { "1", 0x031 },
288
    { "2", 0x032 },
289
    { "3", 0x033 },
290
    { "4", 0x034 },
291
    { "5", 0x035 },
292
    { "6", 0x036 },
293
    { "7", 0x037 },
294
    { "8", 0x038 },
295
    { "9", 0x039 },
296
    { "colon", 0x03a },
297
    { "semicolon", 0x03b },
298
    { "less", 0x03c },
299
    { "equal", 0x03d },
300
    { "greater", 0x03e },
301
    { "question", 0x03f },
302
    { "at", 0x040 },
303
    { "A", 0x041 },
304
    { "B", 0x042 },
305
    { "C", 0x043 },
306
    { "D", 0x044 },
307
    { "E", 0x045 },
308
    { "F", 0x046 },
309
    { "G", 0x047 },
310
    { "H", 0x048 },
311
    { "I", 0x049 },
312
    { "J", 0x04a },
313
    { "K", 0x04b },
314
    { "L", 0x04c },
315
    { "M", 0x04d },
316
    { "N", 0x04e },
317
    { "O", 0x04f },
318
    { "P", 0x050 },
319
    { "Q", 0x051 },
320
    { "R", 0x052 },
321
    { "S", 0x053 },
322
    { "T", 0x054 },
323
    { "U", 0x055 },
324
    { "V", 0x056 },
325
    { "W", 0x057 },
326
    { "X", 0x058 },
327
    { "Y", 0x059 },
328
    { "Z", 0x05a },
329
    { "bracketleft", 0x05b },
330
    { "backslash", 0x05c },
331
    { "bracketright", 0x05d },
332
    { "asciicircum", 0x05e },
333
    { "underscore", 0x05f },
334
    { "grave", 0x060 },
335
    { "a", 0x061 },
336
    { "b", 0x062 },
337
    { "c", 0x063 },
338
    { "d", 0x064 },
339
    { "e", 0x065 },
340
    { "f", 0x066 },
341
    { "g", 0x067 },
342
    { "h", 0x068 },
343
    { "i", 0x069 },
344
    { "j", 0x06a },
345
    { "k", 0x06b },
346
    { "l", 0x06c },
347
    { "m", 0x06d },
348
    { "n", 0x06e },
349
    { "o", 0x06f },
350
    { "p", 0x070 },
351
    { "q", 0x071 },
352
    { "r", 0x072 },
353
    { "s", 0x073 },
354
    { "t", 0x074 },
355
    { "u", 0x075 },
356
    { "v", 0x076 },
357
    { "w", 0x077 },
358
    { "x", 0x078 },
359
    { "y", 0x079 },
360
    { "z", 0x07a },
361
    { "braceleft", 0x07b },
362
    { "bar", 0x07c },
363
    { "braceright", 0x07d },
364
    { "asciitilde", 0x07e },
365

    
366
    /* Latin-1 extensions */
367
    { "nobreakspace", 0x0a0 },
368
    { "exclamdown", 0x0a1 },
369
    { "cent", 0x0a2 },
370
    { "sterling", 0x0a3 },
371
    { "currency", 0x0a4 },
372
    { "yen", 0x0a5 },
373
    { "brokenbar", 0x0a6 },
374
    { "section", 0x0a7 },
375
    { "diaeresis", 0x0a8 },
376
    { "copyright", 0x0a9 },
377
    { "ordfeminine", 0x0aa },
378
    { "guillemotleft", 0x0ab },
379
    { "notsign", 0x0ac },
380
    { "hyphen", 0x0ad },
381
    { "registered", 0x0ae },
382
    { "macron", 0x0af },
383
    { "degree", 0x0b0 },
384
    { "plusminus", 0x0b1 },
385
    { "twosuperior", 0x0b2 },
386
    { "threesuperior", 0x0b3 },
387
    { "acute", 0x0b4 },
388
    { "mu", 0x0b5 },
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 },
399
    { "Agrave", 0x0c0 },
400
    { "Aacute", 0x0c1 },
401
    { "Acircumflex", 0x0c2 },
402
    { "Atilde", 0x0c3 },
403
    { "Adiaeresis", 0x0c4 },
404
    { "Aring", 0x0c5 },
405
    { "AE", 0x0c6 },
406
    { "Ccedilla", 0x0c7 },
407
    { "Egrave", 0x0c8 },
408
    { "Eacute", 0x0c9 },
409
    { "Ecircumflex", 0x0ca },
410
    { "Ediaeresis", 0x0cb },
411
    { "Igrave", 0x0cc },
412
    { "Iacute", 0x0cd },
413
    { "Icircumflex", 0x0ce },
414
    { "Idiaeresis", 0x0cf },
415
    { "ETH", 0x0d0 },
416
    { "Eth", 0x0d0 },
417
    { "Ntilde", 0x0d1 },
418
    { "Ograve", 0x0d2 },
419
    { "Oacute", 0x0d3 },
420
    { "Ocircumflex", 0x0d4 },
421
    { "Otilde", 0x0d5 },
422
    { "Odiaeresis", 0x0d6 },
423
    { "multiply", 0x0d7 },
424
    { "Ooblique", 0x0d8 },
425
    { "Oslash", 0x0d8 },
426
    { "Ugrave", 0x0d9 },
427
    { "Uacute", 0x0da },
428
    { "Ucircumflex", 0x0db },
429
    { "Udiaeresis", 0x0dc },
430
    { "Yacute", 0x0dd },
431
    { "THORN", 0x0de },
432
    { "Thorn", 0x0de },
433
    { "ssharp", 0x0df },
434
    { "agrave", 0x0e0 },
435
    { "aacute", 0x0e1 },
436
    { "acircumflex", 0x0e2 },
437
    { "atilde", 0x0e3 },
438
    { "adiaeresis", 0x0e4 },
439
    { "aring", 0x0e5 },
440
    { "ae", 0x0e6 },
441
    { "ccedilla", 0x0e7 },
442
    { "egrave", 0x0e8 },
443
    { "eacute", 0x0e9 },
444
    { "ecircumflex", 0x0ea },
445
    { "ediaeresis", 0x0eb },
446
    { "igrave", 0x0ec },
447
    { "iacute", 0x0ed },
448
    { "icircumflex", 0x0ee },
449
    { "idiaeresis", 0x0ef },
450
    { "eth", 0x0f0 },
451
    { "ntilde", 0x0f1 },
452
    { "ograve", 0x0f2 },
453
    { "oacute", 0x0f3 },
454
    { "ocircumflex", 0x0f4 },
455
    { "otilde", 0x0f5 },
456
    { "odiaeresis", 0x0f6 },
457
    { "division", 0x0f7 },
458
    { "oslash", 0x0f8 },
459
    { "ooblique", 0x0f8 },
460
    { "ugrave", 0x0f9 },
461
    { "uacute", 0x0fa },
462
    { "ucircumflex", 0x0fb },
463
    { "udiaeresis", 0x0fc },
464
    { "yacute", 0x0fd },
465
    { "thorn", 0x0fe },
466
    { "ydiaeresis", 0x0ff },
467

    
468
    /* Special keys */
469
    { "BackSpace", KEY_BACKSPACE },
470
    { "Tab", '\t' },
471
    { "Return", KEY_ENTER },
472
    { "Right", KEY_RIGHT },
473
    { "Left", KEY_LEFT },
474
    { "Up", KEY_UP },
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 },
481
    { "End", KEY_END },
482
    { "F1", KEY_F(1) },
483
    { "F2", KEY_F(2) },
484
    { "F3", KEY_F(3) },
485
    { "F4", KEY_F(4) },
486
    { "F5", KEY_F(5) },
487
    { "F6", KEY_F(6) },
488
    { "F7", KEY_F(7) },
489
    { "F8", KEY_F(8) },
490
    { "F9", KEY_F(9) },
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) },
506
    { "Escape", 27 },
507

    
508
    { NULL, 0 },
509
};