1 #include "sysemu/sysemu.h" 2 #include "ui/keymaps.h" 3 #include "ui/input.h" 4 5 static const int qcode_to_number[] = { 6 [Q_KEY_CODE_SHIFT] = 0x2a, 7 [Q_KEY_CODE_SHIFT_R] = 0x36, 8 9 [Q_KEY_CODE_ALT] = 0x38, 10 [Q_KEY_CODE_ALT_R] = 0xb8, 11 [Q_KEY_CODE_ALTGR] = 0x64, 12 [Q_KEY_CODE_ALTGR_R] = 0xe4, 13 [Q_KEY_CODE_CTRL] = 0x1d, 14 [Q_KEY_CODE_CTRL_R] = 0x9d, 15 16 [Q_KEY_CODE_MENU] = 0xdd, 17 18 [Q_KEY_CODE_ESC] = 0x01, 19 20 [Q_KEY_CODE_1] = 0x02, 21 [Q_KEY_CODE_2] = 0x03, 22 [Q_KEY_CODE_3] = 0x04, 23 [Q_KEY_CODE_4] = 0x05, 24 [Q_KEY_CODE_5] = 0x06, 25 [Q_KEY_CODE_6] = 0x07, 26 [Q_KEY_CODE_7] = 0x08, 27 [Q_KEY_CODE_8] = 0x09, 28 [Q_KEY_CODE_9] = 0x0a, 29 [Q_KEY_CODE_0] = 0x0b, 30 [Q_KEY_CODE_MINUS] = 0x0c, 31 [Q_KEY_CODE_EQUAL] = 0x0d, 32 [Q_KEY_CODE_BACKSPACE] = 0x0e, 33 34 [Q_KEY_CODE_TAB] = 0x0f, 35 [Q_KEY_CODE_Q] = 0x10, 36 [Q_KEY_CODE_W] = 0x11, 37 [Q_KEY_CODE_E] = 0x12, 38 [Q_KEY_CODE_R] = 0x13, 39 [Q_KEY_CODE_T] = 0x14, 40 [Q_KEY_CODE_Y] = 0x15, 41 [Q_KEY_CODE_U] = 0x16, 42 [Q_KEY_CODE_I] = 0x17, 43 [Q_KEY_CODE_O] = 0x18, 44 [Q_KEY_CODE_P] = 0x19, 45 [Q_KEY_CODE_BRACKET_LEFT] = 0x1a, 46 [Q_KEY_CODE_BRACKET_RIGHT] = 0x1b, 47 [Q_KEY_CODE_RET] = 0x1c, 48 49 [Q_KEY_CODE_A] = 0x1e, 50 [Q_KEY_CODE_S] = 0x1f, 51 [Q_KEY_CODE_D] = 0x20, 52 [Q_KEY_CODE_F] = 0x21, 53 [Q_KEY_CODE_G] = 0x22, 54 [Q_KEY_CODE_H] = 0x23, 55 [Q_KEY_CODE_J] = 0x24, 56 [Q_KEY_CODE_K] = 0x25, 57 [Q_KEY_CODE_L] = 0x26, 58 [Q_KEY_CODE_SEMICOLON] = 0x27, 59 [Q_KEY_CODE_APOSTROPHE] = 0x28, 60 [Q_KEY_CODE_GRAVE_ACCENT] = 0x29, 61 62 [Q_KEY_CODE_BACKSLASH] = 0x2b, 63 [Q_KEY_CODE_Z] = 0x2c, 64 [Q_KEY_CODE_X] = 0x2d, 65 [Q_KEY_CODE_C] = 0x2e, 66 [Q_KEY_CODE_V] = 0x2f, 67 [Q_KEY_CODE_B] = 0x30, 68 [Q_KEY_CODE_N] = 0x31, 69 [Q_KEY_CODE_M] = 0x32, 70 [Q_KEY_CODE_COMMA] = 0x33, 71 [Q_KEY_CODE_DOT] = 0x34, 72 [Q_KEY_CODE_SLASH] = 0x35, 73 74 [Q_KEY_CODE_ASTERISK] = 0x37, 75 76 [Q_KEY_CODE_SPC] = 0x39, 77 [Q_KEY_CODE_CAPS_LOCK] = 0x3a, 78 [Q_KEY_CODE_F1] = 0x3b, 79 [Q_KEY_CODE_F2] = 0x3c, 80 [Q_KEY_CODE_F3] = 0x3d, 81 [Q_KEY_CODE_F4] = 0x3e, 82 [Q_KEY_CODE_F5] = 0x3f, 83 [Q_KEY_CODE_F6] = 0x40, 84 [Q_KEY_CODE_F7] = 0x41, 85 [Q_KEY_CODE_F8] = 0x42, 86 [Q_KEY_CODE_F9] = 0x43, 87 [Q_KEY_CODE_F10] = 0x44, 88 [Q_KEY_CODE_NUM_LOCK] = 0x45, 89 [Q_KEY_CODE_SCROLL_LOCK] = 0x46, 90 91 [Q_KEY_CODE_KP_DIVIDE] = 0xb5, 92 [Q_KEY_CODE_KP_MULTIPLY] = 0x37, 93 [Q_KEY_CODE_KP_SUBTRACT] = 0x4a, 94 [Q_KEY_CODE_KP_ADD] = 0x4e, 95 [Q_KEY_CODE_KP_ENTER] = 0x9c, 96 [Q_KEY_CODE_KP_DECIMAL] = 0x53, 97 [Q_KEY_CODE_SYSRQ] = 0x54, 98 99 [Q_KEY_CODE_KP_0] = 0x52, 100 [Q_KEY_CODE_KP_1] = 0x4f, 101 [Q_KEY_CODE_KP_2] = 0x50, 102 [Q_KEY_CODE_KP_3] = 0x51, 103 [Q_KEY_CODE_KP_4] = 0x4b, 104 [Q_KEY_CODE_KP_5] = 0x4c, 105 [Q_KEY_CODE_KP_6] = 0x4d, 106 [Q_KEY_CODE_KP_7] = 0x47, 107 [Q_KEY_CODE_KP_8] = 0x48, 108 [Q_KEY_CODE_KP_9] = 0x49, 109 110 [Q_KEY_CODE_LESS] = 0x56, 111 112 [Q_KEY_CODE_F11] = 0x57, 113 [Q_KEY_CODE_F12] = 0x58, 114 115 [Q_KEY_CODE_PRINT] = 0xb7, 116 117 [Q_KEY_CODE_HOME] = 0xc7, 118 [Q_KEY_CODE_PGUP] = 0xc9, 119 [Q_KEY_CODE_PGDN] = 0xd1, 120 [Q_KEY_CODE_END] = 0xcf, 121 122 [Q_KEY_CODE_LEFT] = 0xcb, 123 [Q_KEY_CODE_UP] = 0xc8, 124 [Q_KEY_CODE_DOWN] = 0xd0, 125 [Q_KEY_CODE_RIGHT] = 0xcd, 126 127 [Q_KEY_CODE_INSERT] = 0xd2, 128 [Q_KEY_CODE_DELETE] = 0xd3, 129 #ifdef NEED_CPU_H 130 #if defined(TARGET_SPARC) && !defined(TARGET_SPARC64) 131 [Q_KEY_CODE_STOP] = 0xf0, 132 [Q_KEY_CODE_AGAIN] = 0xf1, 133 [Q_KEY_CODE_PROPS] = 0xf2, 134 [Q_KEY_CODE_UNDO] = 0xf3, 135 [Q_KEY_CODE_FRONT] = 0xf4, 136 [Q_KEY_CODE_COPY] = 0xf5, 137 [Q_KEY_CODE_OPEN] = 0xf6, 138 [Q_KEY_CODE_PASTE] = 0xf7, 139 [Q_KEY_CODE_FIND] = 0xf8, 140 [Q_KEY_CODE_CUT] = 0xf9, 141 [Q_KEY_CODE_LF] = 0xfa, 142 [Q_KEY_CODE_HELP] = 0xfb, 143 [Q_KEY_CODE_META_L] = 0xfc, 144 [Q_KEY_CODE_META_R] = 0xfd, 145 [Q_KEY_CODE_COMPOSE] = 0xfe, 146 #endif 147 #endif 148 [Q_KEY_CODE_MAX] = 0, 149 }; 150 151 static int number_to_qcode[0xff]; 152 153 int qemu_input_key_value_to_number(const KeyValue *value) 154 { 155 if (value->kind == KEY_VALUE_KIND_QCODE) { 156 return qcode_to_number[value->qcode]; 157 } else { 158 assert(value->kind == KEY_VALUE_KIND_NUMBER); 159 return value->number; 160 } 161 } 162 163 int qemu_input_key_value_to_qcode(const KeyValue *value) 164 { 165 static int first = true; 166 167 if (first) { 168 int qcode, number; 169 first = false; 170 for (qcode = 0; qcode < Q_KEY_CODE_MAX; qcode++) { 171 number = qcode_to_number[qcode]; 172 assert(number < ARRAY_SIZE(number_to_qcode)); 173 number_to_qcode[number] = qcode; 174 } 175 } 176 177 if (value->kind == KEY_VALUE_KIND_QCODE) { 178 return value->qcode; 179 } else { 180 assert(value->kind == KEY_VALUE_KIND_NUMBER); 181 return number_to_qcode[value->number]; 182 } 183 } 184 185 int qemu_input_key_value_to_scancode(const KeyValue *value, bool down, 186 int *codes) 187 { 188 int keycode = qemu_input_key_value_to_number(value); 189 int count = 0; 190 191 if (value->kind == KEY_VALUE_KIND_QCODE && 192 value->qcode == Q_KEY_CODE_PAUSE) { 193 /* specific case */ 194 int v = down ? 0 : 0x80; 195 codes[count++] = 0xe1; 196 codes[count++] = 0x1d | v; 197 codes[count++] = 0x45 | v; 198 return count; 199 } 200 if (keycode & SCANCODE_GREY) { 201 codes[count++] = SCANCODE_EMUL0; 202 keycode &= ~SCANCODE_GREY; 203 } 204 if (!down) { 205 keycode |= SCANCODE_UP; 206 } 207 codes[count++] = keycode; 208 209 return count; 210 } 211