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