1 #include "sysemu/sysemu.h"
2 #include "ui/keymaps.h"
5 static const int qcode_to_number
[] = {
6 [Q_KEY_CODE_SHIFT
] = 0x2a,
7 [Q_KEY_CODE_SHIFT_R
] = 0x36,
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,
16 [Q_KEY_CODE_META_L
] = 0xdb,
17 [Q_KEY_CODE_META_R
] = 0xdc,
18 [Q_KEY_CODE_MENU
] = 0xdd,
20 [Q_KEY_CODE_ESC
] = 0x01,
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,
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,
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,
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,
76 [Q_KEY_CODE_ASTERISK
] = 0x37,
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,
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,
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,
112 [Q_KEY_CODE_LESS
] = 0x56,
114 [Q_KEY_CODE_F11
] = 0x57,
115 [Q_KEY_CODE_F12
] = 0x58,
117 [Q_KEY_CODE_PRINT
] = 0xb7,
119 [Q_KEY_CODE_HOME
] = 0xc7,
120 [Q_KEY_CODE_PGUP
] = 0xc9,
121 [Q_KEY_CODE_PGDN
] = 0xd1,
122 [Q_KEY_CODE_END
] = 0xcf,
124 [Q_KEY_CODE_LEFT
] = 0xcb,
125 [Q_KEY_CODE_UP
] = 0xc8,
126 [Q_KEY_CODE_DOWN
] = 0xd0,
127 [Q_KEY_CODE_RIGHT
] = 0xcd,
129 [Q_KEY_CODE_INSERT
] = 0xd2,
130 [Q_KEY_CODE_DELETE
] = 0xd3,
131 [Q_KEY_CODE_MAX
] = 0,
134 static int number_to_qcode
[0x100];
136 int qemu_input_key_value_to_number(const KeyValue
*value
)
138 if (value
->kind
== KEY_VALUE_KIND_QCODE
) {
139 return qcode_to_number
[value
->qcode
];
141 assert(value
->kind
== KEY_VALUE_KIND_NUMBER
);
142 return value
->number
;
146 int qemu_input_key_number_to_qcode(uint8_t nr
)
148 static int first
= true;
153 for (qcode
= 0; qcode
< Q_KEY_CODE_MAX
; qcode
++) {
154 number
= qcode_to_number
[qcode
];
155 assert(number
< ARRAY_SIZE(number_to_qcode
));
156 number_to_qcode
[number
] = qcode
;
160 return number_to_qcode
[nr
];
163 int qemu_input_key_value_to_qcode(const KeyValue
*value
)
165 if (value
->kind
== KEY_VALUE_KIND_QCODE
) {
168 assert(value
->kind
== KEY_VALUE_KIND_NUMBER
);
169 return qemu_input_key_number_to_qcode(value
->number
);
173 int qemu_input_key_value_to_scancode(const KeyValue
*value
, bool down
,
176 int keycode
= qemu_input_key_value_to_number(value
);
179 if (value
->kind
== KEY_VALUE_KIND_QCODE
&&
180 value
->qcode
== Q_KEY_CODE_PAUSE
) {
182 int v
= down
? 0 : 0x80;
183 codes
[count
++] = 0xe1;
184 codes
[count
++] = 0x1d | v
;
185 codes
[count
++] = 0x45 | v
;
188 if (keycode
& SCANCODE_GREY
) {
189 codes
[count
++] = SCANCODE_EMUL0
;
190 keycode
&= ~SCANCODE_GREY
;
193 keycode
|= SCANCODE_UP
;
195 codes
[count
++] = keycode
;