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