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