s390x: sort some devices into categories
[qemu.git] / ui / input-keymap.c
blobcf979c2ce99dc4549d30a314475f2ea78b92fa88
1 #include "qemu/osdep.h"
2 #include "sysemu/sysemu.h"
3 #include "ui/keymaps.h"
4 #include "ui/input.h"
6 #include "standard-headers/linux/input.h"
8 static int linux_to_qcode[KEY_CNT] = {
9 [KEY_ESC] = Q_KEY_CODE_ESC,
10 [KEY_1] = Q_KEY_CODE_1,
11 [KEY_2] = Q_KEY_CODE_2,
12 [KEY_3] = Q_KEY_CODE_3,
13 [KEY_4] = Q_KEY_CODE_4,
14 [KEY_5] = Q_KEY_CODE_5,
15 [KEY_6] = Q_KEY_CODE_6,
16 [KEY_7] = Q_KEY_CODE_7,
17 [KEY_8] = Q_KEY_CODE_8,
18 [KEY_9] = Q_KEY_CODE_9,
19 [KEY_0] = Q_KEY_CODE_0,
20 [KEY_MINUS] = Q_KEY_CODE_MINUS,
21 [KEY_EQUAL] = Q_KEY_CODE_EQUAL,
22 [KEY_BACKSPACE] = Q_KEY_CODE_BACKSPACE,
23 [KEY_TAB] = Q_KEY_CODE_TAB,
24 [KEY_Q] = Q_KEY_CODE_Q,
25 [KEY_W] = Q_KEY_CODE_W,
26 [KEY_E] = Q_KEY_CODE_E,
27 [KEY_R] = Q_KEY_CODE_R,
28 [KEY_T] = Q_KEY_CODE_T,
29 [KEY_Y] = Q_KEY_CODE_Y,
30 [KEY_U] = Q_KEY_CODE_U,
31 [KEY_I] = Q_KEY_CODE_I,
32 [KEY_O] = Q_KEY_CODE_O,
33 [KEY_P] = Q_KEY_CODE_P,
34 [KEY_LEFTBRACE] = Q_KEY_CODE_BRACKET_LEFT,
35 [KEY_RIGHTBRACE] = Q_KEY_CODE_BRACKET_RIGHT,
36 [KEY_ENTER] = Q_KEY_CODE_RET,
37 [KEY_LEFTCTRL] = Q_KEY_CODE_CTRL,
38 [KEY_A] = Q_KEY_CODE_A,
39 [KEY_S] = Q_KEY_CODE_S,
40 [KEY_D] = Q_KEY_CODE_D,
41 [KEY_F] = Q_KEY_CODE_F,
42 [KEY_G] = Q_KEY_CODE_G,
43 [KEY_H] = Q_KEY_CODE_H,
44 [KEY_J] = Q_KEY_CODE_J,
45 [KEY_K] = Q_KEY_CODE_K,
46 [KEY_L] = Q_KEY_CODE_L,
47 [KEY_SEMICOLON] = Q_KEY_CODE_SEMICOLON,
48 [KEY_APOSTROPHE] = Q_KEY_CODE_APOSTROPHE,
49 [KEY_GRAVE] = Q_KEY_CODE_GRAVE_ACCENT,
50 [KEY_LEFTSHIFT] = Q_KEY_CODE_SHIFT,
51 [KEY_BACKSLASH] = Q_KEY_CODE_BACKSLASH,
52 [KEY_102ND] = Q_KEY_CODE_LESS,
53 [KEY_Z] = Q_KEY_CODE_Z,
54 [KEY_X] = Q_KEY_CODE_X,
55 [KEY_C] = Q_KEY_CODE_C,
56 [KEY_V] = Q_KEY_CODE_V,
57 [KEY_B] = Q_KEY_CODE_B,
58 [KEY_N] = Q_KEY_CODE_N,
59 [KEY_M] = Q_KEY_CODE_M,
60 [KEY_COMMA] = Q_KEY_CODE_COMMA,
61 [KEY_DOT] = Q_KEY_CODE_DOT,
62 [KEY_SLASH] = Q_KEY_CODE_SLASH,
63 [KEY_RIGHTSHIFT] = Q_KEY_CODE_SHIFT_R,
64 [KEY_LEFTALT] = Q_KEY_CODE_ALT,
65 [KEY_SPACE] = Q_KEY_CODE_SPC,
66 [KEY_CAPSLOCK] = Q_KEY_CODE_CAPS_LOCK,
67 [KEY_F1] = Q_KEY_CODE_F1,
68 [KEY_F2] = Q_KEY_CODE_F2,
69 [KEY_F3] = Q_KEY_CODE_F3,
70 [KEY_F4] = Q_KEY_CODE_F4,
71 [KEY_F5] = Q_KEY_CODE_F5,
72 [KEY_F6] = Q_KEY_CODE_F6,
73 [KEY_F7] = Q_KEY_CODE_F7,
74 [KEY_F8] = Q_KEY_CODE_F8,
75 [KEY_F9] = Q_KEY_CODE_F9,
76 [KEY_F10] = Q_KEY_CODE_F10,
77 [KEY_NUMLOCK] = Q_KEY_CODE_NUM_LOCK,
78 [KEY_SCROLLLOCK] = Q_KEY_CODE_SCROLL_LOCK,
79 [KEY_KP0] = Q_KEY_CODE_KP_0,
80 [KEY_KP1] = Q_KEY_CODE_KP_1,
81 [KEY_KP2] = Q_KEY_CODE_KP_2,
82 [KEY_KP3] = Q_KEY_CODE_KP_3,
83 [KEY_KP4] = Q_KEY_CODE_KP_4,
84 [KEY_KP5] = Q_KEY_CODE_KP_5,
85 [KEY_KP6] = Q_KEY_CODE_KP_6,
86 [KEY_KP7] = Q_KEY_CODE_KP_7,
87 [KEY_KP8] = Q_KEY_CODE_KP_8,
88 [KEY_KP9] = Q_KEY_CODE_KP_9,
89 [KEY_KPMINUS] = Q_KEY_CODE_KP_SUBTRACT,
90 [KEY_KPPLUS] = Q_KEY_CODE_KP_ADD,
91 [KEY_KPDOT] = Q_KEY_CODE_KP_DECIMAL,
92 [KEY_KPENTER] = Q_KEY_CODE_KP_ENTER,
93 [KEY_KPSLASH] = Q_KEY_CODE_KP_DIVIDE,
94 [KEY_KPASTERISK] = Q_KEY_CODE_KP_MULTIPLY,
95 [KEY_F11] = Q_KEY_CODE_F11,
96 [KEY_F12] = Q_KEY_CODE_F12,
97 [KEY_RO] = Q_KEY_CODE_RO,
98 [KEY_HIRAGANA] = Q_KEY_CODE_HIRAGANA,
99 [KEY_HENKAN] = Q_KEY_CODE_HENKAN,
100 [KEY_RIGHTCTRL] = Q_KEY_CODE_CTRL_R,
101 [KEY_SYSRQ] = Q_KEY_CODE_SYSRQ,
102 [KEY_RIGHTALT] = Q_KEY_CODE_ALT_R,
103 [KEY_HOME] = Q_KEY_CODE_HOME,
104 [KEY_UP] = Q_KEY_CODE_UP,
105 [KEY_PAGEUP] = Q_KEY_CODE_PGUP,
106 [KEY_LEFT] = Q_KEY_CODE_LEFT,
107 [KEY_RIGHT] = Q_KEY_CODE_RIGHT,
108 [KEY_END] = Q_KEY_CODE_END,
109 [KEY_DOWN] = Q_KEY_CODE_DOWN,
110 [KEY_PAGEDOWN] = Q_KEY_CODE_PGDN,
111 [KEY_INSERT] = Q_KEY_CODE_INSERT,
112 [KEY_DELETE] = Q_KEY_CODE_DELETE,
113 [KEY_POWER] = Q_KEY_CODE_POWER,
114 [KEY_KPCOMMA] = Q_KEY_CODE_KP_COMMA,
115 [KEY_YEN] = Q_KEY_CODE_YEN,
116 [KEY_LEFTMETA] = Q_KEY_CODE_META_L,
117 [KEY_RIGHTMETA] = Q_KEY_CODE_META_R,
118 [KEY_MENU] = Q_KEY_CODE_MENU,
119 [KEY_PAUSE] = Q_KEY_CODE_PAUSE,
121 [KEY_SLEEP] = Q_KEY_CODE_SLEEP,
122 [KEY_WAKEUP] = Q_KEY_CODE_WAKE,
123 [KEY_CALC] = Q_KEY_CODE_CALCULATOR,
124 [KEY_MAIL] = Q_KEY_CODE_MAIL,
125 [KEY_COMPUTER] = Q_KEY_CODE_COMPUTER,
127 [KEY_STOP] = Q_KEY_CODE_STOP,
128 [KEY_BOOKMARKS] = Q_KEY_CODE_AC_BOOKMARKS,
129 [KEY_BACK] = Q_KEY_CODE_AC_BACK,
130 [KEY_FORWARD] = Q_KEY_CODE_AC_FORWARD,
131 [KEY_HOMEPAGE] = Q_KEY_CODE_AC_HOME,
132 [KEY_REFRESH] = Q_KEY_CODE_AC_REFRESH,
133 [KEY_FIND] = Q_KEY_CODE_FIND,
135 [KEY_NEXTSONG] = Q_KEY_CODE_AUDIONEXT,
136 [KEY_PREVIOUSSONG] = Q_KEY_CODE_AUDIOPREV,
137 [KEY_STOPCD] = Q_KEY_CODE_AUDIOSTOP,
138 [KEY_PLAYCD] = Q_KEY_CODE_AUDIOPLAY,
139 [KEY_MUTE] = Q_KEY_CODE_AUDIOMUTE,
140 [KEY_VOLUMEDOWN] = Q_KEY_CODE_VOLUMEDOWN,
141 [KEY_VOLUMEUP] = Q_KEY_CODE_VOLUMEUP,
144 static const int qcode_to_number[] = {
145 [Q_KEY_CODE_SHIFT] = 0x2a,
146 [Q_KEY_CODE_SHIFT_R] = 0x36,
148 [Q_KEY_CODE_ALT] = 0x38,
149 [Q_KEY_CODE_ALT_R] = 0xb8,
150 [Q_KEY_CODE_CTRL] = 0x1d,
151 [Q_KEY_CODE_CTRL_R] = 0x9d,
153 [Q_KEY_CODE_META_L] = 0xdb,
154 [Q_KEY_CODE_META_R] = 0xdc,
155 [Q_KEY_CODE_MENU] = 0xdd,
157 [Q_KEY_CODE_ESC] = 0x01,
159 [Q_KEY_CODE_1] = 0x02,
160 [Q_KEY_CODE_2] = 0x03,
161 [Q_KEY_CODE_3] = 0x04,
162 [Q_KEY_CODE_4] = 0x05,
163 [Q_KEY_CODE_5] = 0x06,
164 [Q_KEY_CODE_6] = 0x07,
165 [Q_KEY_CODE_7] = 0x08,
166 [Q_KEY_CODE_8] = 0x09,
167 [Q_KEY_CODE_9] = 0x0a,
168 [Q_KEY_CODE_0] = 0x0b,
169 [Q_KEY_CODE_MINUS] = 0x0c,
170 [Q_KEY_CODE_EQUAL] = 0x0d,
171 [Q_KEY_CODE_BACKSPACE] = 0x0e,
173 [Q_KEY_CODE_TAB] = 0x0f,
174 [Q_KEY_CODE_Q] = 0x10,
175 [Q_KEY_CODE_W] = 0x11,
176 [Q_KEY_CODE_E] = 0x12,
177 [Q_KEY_CODE_R] = 0x13,
178 [Q_KEY_CODE_T] = 0x14,
179 [Q_KEY_CODE_Y] = 0x15,
180 [Q_KEY_CODE_U] = 0x16,
181 [Q_KEY_CODE_I] = 0x17,
182 [Q_KEY_CODE_O] = 0x18,
183 [Q_KEY_CODE_P] = 0x19,
184 [Q_KEY_CODE_BRACKET_LEFT] = 0x1a,
185 [Q_KEY_CODE_BRACKET_RIGHT] = 0x1b,
186 [Q_KEY_CODE_RET] = 0x1c,
188 [Q_KEY_CODE_A] = 0x1e,
189 [Q_KEY_CODE_S] = 0x1f,
190 [Q_KEY_CODE_D] = 0x20,
191 [Q_KEY_CODE_F] = 0x21,
192 [Q_KEY_CODE_G] = 0x22,
193 [Q_KEY_CODE_H] = 0x23,
194 [Q_KEY_CODE_J] = 0x24,
195 [Q_KEY_CODE_K] = 0x25,
196 [Q_KEY_CODE_L] = 0x26,
197 [Q_KEY_CODE_SEMICOLON] = 0x27,
198 [Q_KEY_CODE_APOSTROPHE] = 0x28,
199 [Q_KEY_CODE_GRAVE_ACCENT] = 0x29,
201 [Q_KEY_CODE_BACKSLASH] = 0x2b,
202 [Q_KEY_CODE_Z] = 0x2c,
203 [Q_KEY_CODE_X] = 0x2d,
204 [Q_KEY_CODE_C] = 0x2e,
205 [Q_KEY_CODE_V] = 0x2f,
206 [Q_KEY_CODE_B] = 0x30,
207 [Q_KEY_CODE_N] = 0x31,
208 [Q_KEY_CODE_M] = 0x32,
209 [Q_KEY_CODE_COMMA] = 0x33,
210 [Q_KEY_CODE_DOT] = 0x34,
211 [Q_KEY_CODE_SLASH] = 0x35,
213 [Q_KEY_CODE_ASTERISK] = 0x37,
215 [Q_KEY_CODE_SPC] = 0x39,
216 [Q_KEY_CODE_CAPS_LOCK] = 0x3a,
217 [Q_KEY_CODE_F1] = 0x3b,
218 [Q_KEY_CODE_F2] = 0x3c,
219 [Q_KEY_CODE_F3] = 0x3d,
220 [Q_KEY_CODE_F4] = 0x3e,
221 [Q_KEY_CODE_F5] = 0x3f,
222 [Q_KEY_CODE_F6] = 0x40,
223 [Q_KEY_CODE_F7] = 0x41,
224 [Q_KEY_CODE_F8] = 0x42,
225 [Q_KEY_CODE_F9] = 0x43,
226 [Q_KEY_CODE_F10] = 0x44,
227 [Q_KEY_CODE_NUM_LOCK] = 0x45,
228 [Q_KEY_CODE_SCROLL_LOCK] = 0x46,
230 [Q_KEY_CODE_KP_DIVIDE] = 0xb5,
231 [Q_KEY_CODE_KP_MULTIPLY] = 0x37,
232 [Q_KEY_CODE_KP_SUBTRACT] = 0x4a,
233 [Q_KEY_CODE_KP_ADD] = 0x4e,
234 [Q_KEY_CODE_KP_ENTER] = 0x9c,
235 [Q_KEY_CODE_KP_DECIMAL] = 0x53,
236 [Q_KEY_CODE_SYSRQ] = 0x54,
237 [Q_KEY_CODE_PAUSE] = 0xc6,
239 [Q_KEY_CODE_KP_0] = 0x52,
240 [Q_KEY_CODE_KP_1] = 0x4f,
241 [Q_KEY_CODE_KP_2] = 0x50,
242 [Q_KEY_CODE_KP_3] = 0x51,
243 [Q_KEY_CODE_KP_4] = 0x4b,
244 [Q_KEY_CODE_KP_5] = 0x4c,
245 [Q_KEY_CODE_KP_6] = 0x4d,
246 [Q_KEY_CODE_KP_7] = 0x47,
247 [Q_KEY_CODE_KP_8] = 0x48,
248 [Q_KEY_CODE_KP_9] = 0x49,
250 [Q_KEY_CODE_LESS] = 0x56,
252 [Q_KEY_CODE_F11] = 0x57,
253 [Q_KEY_CODE_F12] = 0x58,
255 [Q_KEY_CODE_PRINT] = 0xb7,
257 [Q_KEY_CODE_HOME] = 0xc7,
258 [Q_KEY_CODE_PGUP] = 0xc9,
259 [Q_KEY_CODE_PGDN] = 0xd1,
260 [Q_KEY_CODE_END] = 0xcf,
262 [Q_KEY_CODE_LEFT] = 0xcb,
263 [Q_KEY_CODE_UP] = 0xc8,
264 [Q_KEY_CODE_DOWN] = 0xd0,
265 [Q_KEY_CODE_RIGHT] = 0xcd,
267 [Q_KEY_CODE_INSERT] = 0xd2,
268 [Q_KEY_CODE_DELETE] = 0xd3,
270 [Q_KEY_CODE_RO] = 0x73,
271 [Q_KEY_CODE_HIRAGANA] = 0x70,
272 [Q_KEY_CODE_HENKAN] = 0x79,
273 [Q_KEY_CODE_POWER] = 0xde,
274 [Q_KEY_CODE_YEN] = 0x7d,
275 [Q_KEY_CODE_KP_COMMA] = 0x7e,
277 [Q_KEY_CODE_SLEEP] = 0xdf,
278 [Q_KEY_CODE_WAKE] = 0xe3,
279 [Q_KEY_CODE_CALCULATOR] = 0xa1,
280 [Q_KEY_CODE_MAIL] = 0xec,
281 [Q_KEY_CODE_COMPUTER] = 0xeb,
283 [Q_KEY_CODE_STOP] = 0xe8,
284 [Q_KEY_CODE_AC_BOOKMARKS] = 0xe6,
285 [Q_KEY_CODE_AC_BACK] = 0xea,
286 [Q_KEY_CODE_AC_FORWARD] = 0xe9,
287 [Q_KEY_CODE_AC_HOME] = 0xb2,
288 [Q_KEY_CODE_AC_REFRESH] = 0xe7,
289 [Q_KEY_CODE_FIND] = 0xe5,
291 [Q_KEY_CODE_AUDIONEXT] = 0x99,
292 [Q_KEY_CODE_AUDIOPREV] = 0x90,
293 [Q_KEY_CODE_AUDIOSTOP] = 0xa4,
294 [Q_KEY_CODE_AUDIOPLAY] = 0xa2,
295 [Q_KEY_CODE_AUDIOMUTE] = 0xa0,
296 [Q_KEY_CODE_VOLUMEDOWN] = 0xae,
297 [Q_KEY_CODE_VOLUMEUP] = 0xb0,
299 [Q_KEY_CODE__MAX] = 0,
302 static int number_to_qcode[0x100];
304 int qemu_input_linux_to_qcode(unsigned int lnx)
306 assert(lnx < KEY_CNT);
307 return linux_to_qcode[lnx];
310 int qemu_input_key_value_to_number(const KeyValue *value)
312 if (value->type == KEY_VALUE_KIND_QCODE) {
313 return qcode_to_number[value->u.qcode.data];
314 } else {
315 assert(value->type == KEY_VALUE_KIND_NUMBER);
316 return value->u.number.data;
320 int qemu_input_key_number_to_qcode(uint8_t nr)
322 static int first = true;
324 if (first) {
325 int qcode, number;
326 first = false;
327 for (qcode = 0; qcode < Q_KEY_CODE__MAX; qcode++) {
328 number = qcode_to_number[qcode];
329 assert(number < ARRAY_SIZE(number_to_qcode));
330 number_to_qcode[number] = qcode;
334 return number_to_qcode[nr];
337 int qemu_input_key_value_to_qcode(const KeyValue *value)
339 if (value->type == KEY_VALUE_KIND_QCODE) {
340 return value->u.qcode.data;
341 } else {
342 assert(value->type == KEY_VALUE_KIND_NUMBER);
343 return qemu_input_key_number_to_qcode(value->u.number.data);
347 int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
348 int *codes)
350 int keycode = qemu_input_key_value_to_number(value);
351 int count = 0;
353 if (value->type == KEY_VALUE_KIND_QCODE &&
354 value->u.qcode.data == Q_KEY_CODE_PAUSE) {
355 /* specific case */
356 int v = down ? 0 : 0x80;
357 codes[count++] = 0xe1;
358 codes[count++] = 0x1d | v;
359 codes[count++] = 0x45 | v;
360 return count;
362 if (keycode & SCANCODE_GREY) {
363 codes[count++] = SCANCODE_EMUL0;
364 keycode &= ~SCANCODE_GREY;
366 if (!down) {
367 keycode |= SCANCODE_UP;
369 codes[count++] = keycode;
371 return count;