20 #include <winpr/config.h>
22 #include <winpr/crt.h>
24 #include <winpr/input.h>
36 static const VIRTUAL_KEY_CODE VIRTUAL_KEY_CODE_TABLE[256] = {
38 { VK_LBUTTON,
"VK_LBUTTON" },
39 { VK_RBUTTON,
"VK_RBUTTON" },
40 { VK_CANCEL,
"VK_CANCEL" },
41 { VK_MBUTTON,
"VK_MBUTTON" },
42 { VK_XBUTTON1,
"VK_XBUTTON1" },
43 { VK_XBUTTON2,
"VK_XBUTTON2" },
45 { VK_BACK,
"VK_BACK" },
49 { VK_CLEAR,
"VK_CLEAR" },
50 { VK_RETURN,
"VK_RETURN" },
53 { VK_SHIFT,
"VK_SHIFT" },
54 { VK_CONTROL,
"VK_CONTROL" },
55 { VK_MENU,
"VK_MENU" },
56 { VK_PAUSE,
"VK_PAUSE" },
57 { VK_CAPITAL,
"VK_CAPITAL" },
58 { VK_KANA,
"VK_KANA" },
60 { VK_JUNJA,
"VK_JUNJA" },
61 { VK_FINAL,
"VK_FINAL" },
62 { VK_KANJI,
"VK_KANJI" },
63 { VK_HKTG,
"VK_HKTG" },
64 { VK_ESCAPE,
"VK_ESCAPE" },
65 { VK_CONVERT,
"VK_CONVERT" },
66 { VK_NONCONVERT,
"VK_NONCONVERT" },
67 { VK_ACCEPT,
"VK_ACCEPT" },
68 { VK_MODECHANGE,
"VK_MODECHANGE" },
69 { VK_SPACE,
"VK_SPACE" },
70 { VK_PRIOR,
"VK_PRIOR" },
71 { VK_NEXT,
"VK_NEXT" },
73 { VK_HOME,
"VK_HOME" },
74 { VK_LEFT,
"VK_LEFT" },
76 { VK_RIGHT,
"VK_RIGHT" },
77 { VK_DOWN,
"VK_DOWN" },
78 { VK_SELECT,
"VK_SELECT" },
79 { VK_PRINT,
"VK_PRINT" },
80 { VK_EXECUTE,
"VK_EXECUTE" },
81 { VK_SNAPSHOT,
"VK_SNAPSHOT" },
82 { VK_INSERT,
"VK_INSERT" },
83 { VK_DELETE,
"VK_DELETE" },
84 { VK_HELP,
"VK_HELP" },
85 { VK_KEY_0,
"VK_KEY_0" },
86 { VK_KEY_1,
"VK_KEY_1" },
87 { VK_KEY_2,
"VK_KEY_2" },
88 { VK_KEY_3,
"VK_KEY_3" },
89 { VK_KEY_4,
"VK_KEY_4" },
90 { VK_KEY_5,
"VK_KEY_5" },
91 { VK_KEY_6,
"VK_KEY_6" },
92 { VK_KEY_7,
"VK_KEY_7" },
93 { VK_KEY_8,
"VK_KEY_8" },
94 { VK_KEY_9,
"VK_KEY_9" },
102 { VK_KEY_A,
"VK_KEY_A" },
103 { VK_KEY_B,
"VK_KEY_B" },
104 { VK_KEY_C,
"VK_KEY_C" },
105 { VK_KEY_D,
"VK_KEY_D" },
106 { VK_KEY_E,
"VK_KEY_E" },
107 { VK_KEY_F,
"VK_KEY_F" },
108 { VK_KEY_G,
"VK_KEY_G" },
109 { VK_KEY_H,
"VK_KEY_H" },
110 { VK_KEY_I,
"VK_KEY_I" },
111 { VK_KEY_J,
"VK_KEY_J" },
112 { VK_KEY_K,
"VK_KEY_K" },
113 { VK_KEY_L,
"VK_KEY_L" },
114 { VK_KEY_M,
"VK_KEY_M" },
115 { VK_KEY_N,
"VK_KEY_N" },
116 { VK_KEY_O,
"VK_KEY_O" },
117 { VK_KEY_P,
"VK_KEY_P" },
118 { VK_KEY_Q,
"VK_KEY_Q" },
119 { VK_KEY_R,
"VK_KEY_R" },
120 { VK_KEY_S,
"VK_KEY_S" },
121 { VK_KEY_T,
"VK_KEY_T" },
122 { VK_KEY_U,
"VK_KEY_U" },
123 { VK_KEY_V,
"VK_KEY_V" },
124 { VK_KEY_W,
"VK_KEY_W" },
125 { VK_KEY_X,
"VK_KEY_X" },
126 { VK_KEY_Y,
"VK_KEY_Y" },
127 { VK_KEY_Z,
"VK_KEY_Z" },
128 { VK_LWIN,
"VK_LWIN" },
129 { VK_RWIN,
"VK_RWIN" },
130 { VK_APPS,
"VK_APPS" },
132 { VK_SLEEP,
"VK_SLEEP" },
133 { VK_NUMPAD0,
"VK_NUMPAD0" },
134 { VK_NUMPAD1,
"VK_NUMPAD1" },
135 { VK_NUMPAD2,
"VK_NUMPAD2" },
136 { VK_NUMPAD3,
"VK_NUMPAD3" },
137 { VK_NUMPAD4,
"VK_NUMPAD4" },
138 { VK_NUMPAD5,
"VK_NUMPAD5" },
139 { VK_NUMPAD6,
"VK_NUMPAD6" },
140 { VK_NUMPAD7,
"VK_NUMPAD7" },
141 { VK_NUMPAD8,
"VK_NUMPAD8" },
142 { VK_NUMPAD9,
"VK_NUMPAD9" },
143 { VK_MULTIPLY,
"VK_MULTIPLY" },
144 { VK_ADD,
"VK_ADD" },
145 { VK_SEPARATOR,
"VK_SEPARATOR" },
146 { VK_SUBTRACT,
"VK_SUBTRACT" },
147 { VK_DECIMAL,
"VK_DECIMAL" },
148 { VK_DIVIDE,
"VK_DIVIDE" },
158 { VK_F10,
"VK_F10" },
159 { VK_F11,
"VK_F11" },
160 { VK_F12,
"VK_F12" },
161 { VK_F13,
"VK_F13" },
162 { VK_F14,
"VK_F14" },
163 { VK_F15,
"VK_F15" },
164 { VK_F16,
"VK_F16" },
165 { VK_F17,
"VK_F17" },
166 { VK_F18,
"VK_F18" },
167 { VK_F19,
"VK_F19" },
168 { VK_F20,
"VK_F20" },
169 { VK_F21,
"VK_F21" },
170 { VK_F22,
"VK_F22" },
171 { VK_F23,
"VK_F23" },
172 { VK_F24,
"VK_F24" },
181 { VK_NUMLOCK,
"VK_NUMLOCK" },
182 { VK_SCROLL,
"VK_SCROLL" },
197 { VK_LSHIFT,
"VK_LSHIFT" },
198 { VK_RSHIFT,
"VK_RSHIFT" },
199 { VK_LCONTROL,
"VK_LCONTROL" },
200 { VK_RCONTROL,
"VK_RCONTROL" },
201 { VK_LMENU,
"VK_LMENU" },
202 { VK_RMENU,
"VK_RMENU" },
203 { VK_BROWSER_BACK,
"VK_BROWSER_BACK" },
204 { VK_BROWSER_FORWARD,
"VK_BROWSER_FORWARD" },
205 { VK_BROWSER_REFRESH,
"VK_BROWSER_REFRESH" },
206 { VK_BROWSER_STOP,
"VK_BROWSER_STOP" },
207 { VK_BROWSER_SEARCH,
"VK_BROWSER_SEARCH" },
208 { VK_BROWSER_FAVORITES,
"VK_BROWSER_FAVORITES" },
209 { VK_BROWSER_HOME,
"VK_BROWSER_HOME" },
210 { VK_VOLUME_MUTE,
"VK_VOLUME_MUTE" },
211 { VK_VOLUME_DOWN,
"VK_VOLUME_DOWN" },
212 { VK_VOLUME_UP,
"VK_VOLUME_UP" },
213 { VK_MEDIA_NEXT_TRACK,
"VK_MEDIA_NEXT_TRACK" },
214 { VK_MEDIA_PREV_TRACK,
"VK_MEDIA_PREV_TRACK" },
215 { VK_MEDIA_STOP,
"VK_MEDIA_STOP" },
216 { VK_MEDIA_PLAY_PAUSE,
"VK_MEDIA_PLAY_PAUSE" },
217 { VK_LAUNCH_MAIL,
"VK_LAUNCH_MAIL" },
218 { VK_MEDIA_SELECT,
"VK_MEDIA_SELECT" },
219 { VK_LAUNCH_APP1,
"VK_LAUNCH_APP1" },
220 { VK_LAUNCH_APP2,
"VK_LAUNCH_APP2" },
223 { VK_OEM_1,
"VK_OEM_1" },
224 { VK_OEM_PLUS,
"VK_OEM_PLUS" },
225 { VK_OEM_COMMA,
"VK_OEM_COMMA" },
226 { VK_OEM_MINUS,
"VK_OEM_MINUS" },
227 { VK_OEM_PERIOD,
"VK_OEM_PERIOD" },
228 { VK_OEM_2,
"VK_OEM_2" },
229 { VK_OEM_3,
"VK_OEM_3" },
230 { VK_ABNT_C1,
"VK_ABNT_C1" },
231 { VK_ABNT_C2,
"VK_ABNT_C2" },
256 { VK_OEM_4,
"VK_OEM_4" },
257 { VK_OEM_5,
"VK_OEM_5" },
258 { VK_OEM_6,
"VK_OEM_6" },
259 { VK_OEM_7,
"VK_OEM_7" },
260 { VK_OEM_8,
"VK_OEM_8" },
263 { VK_OEM_102,
"VK_OEM_102" },
266 { VK_PROCESSKEY,
"VK_PROCESSKEY" },
268 { VK_PACKET,
"VK_PACKET" },
283 { VK_ATTN,
"VK_ATTN" },
284 { VK_CRSEL,
"VK_CRSEL" },
285 { VK_EXSEL,
"VK_EXSEL" },
286 { VK_EREOF,
"VK_EREOF" },
287 { VK_PLAY,
"VK_PLAY" },
288 { VK_ZOOM,
"VK_ZOOM" },
289 { VK_NONAME,
"VK_NONAME" },
290 { VK_PA1,
"VK_PA1" },
291 { VK_OEM_CLEAR,
"VK_OEM_CLEAR" },
301 static XKB_KEYNAME XKB_KEYNAME_TABLE[] = {
304 {
"RTRN", VK_RETURN },
305 {
"LFSH", VK_LSHIFT },
306 {
"LALT", VK_LMENU },
307 {
"CAPS", VK_CAPITAL },
308 {
"ESC", VK_ESCAPE },
309 {
"SPCE", VK_SPACE },
310 {
"AE10", VK_KEY_0 },
311 {
"AE01", VK_KEY_1 },
312 {
"AE02", VK_KEY_2 },
313 {
"AE03", VK_KEY_3 },
314 {
"AE04", VK_KEY_4 },
315 {
"AE05", VK_KEY_5 },
316 {
"AE06", VK_KEY_6 },
317 {
"AE07", VK_KEY_7 },
318 {
"AE08", VK_KEY_8 },
319 {
"AE09", VK_KEY_9 },
320 {
"AC01", VK_KEY_A },
321 {
"AB05", VK_KEY_B },
322 {
"AB03", VK_KEY_C },
323 {
"AC03", VK_KEY_D },
324 {
"AD03", VK_KEY_E },
325 {
"AC04", VK_KEY_F },
326 {
"AC05", VK_KEY_G },
327 {
"AC06", VK_KEY_H },
328 {
"AD08", VK_KEY_I },
329 {
"AC07", VK_KEY_J },
330 {
"AC08", VK_KEY_K },
331 {
"AC09", VK_KEY_L },
332 {
"AB07", VK_KEY_M },
333 {
"AB06", VK_KEY_N },
334 {
"AD09", VK_KEY_O },
335 {
"AD10", VK_KEY_P },
336 {
"AD01", VK_KEY_Q },
337 {
"AD04", VK_KEY_R },
338 {
"AC02", VK_KEY_S },
339 {
"AD05", VK_KEY_T },
340 {
"AD07", VK_KEY_U },
341 {
"AB04", VK_KEY_V },
342 {
"AD02", VK_KEY_W },
343 {
"AB02", VK_KEY_X },
344 {
"AD06", VK_KEY_Y },
345 {
"AB01", VK_KEY_Z },
346 {
"KP0", VK_NUMPAD0 },
347 {
"KP1", VK_NUMPAD1 },
348 {
"KP2", VK_NUMPAD2 },
349 {
"KP3", VK_NUMPAD3 },
350 {
"KP4", VK_NUMPAD4 },
351 {
"KP5", VK_NUMPAD5 },
352 {
"KP6", VK_NUMPAD6 },
353 {
"KP7", VK_NUMPAD7 },
354 {
"KP8", VK_NUMPAD8 },
355 {
"KP9", VK_NUMPAD9 },
356 {
"KPMU", VK_MULTIPLY },
358 {
"KPSU", VK_SUBTRACT },
359 {
"KPDL", VK_DECIMAL },
360 {
"AB10", VK_OEM_2 },
373 {
"NMLK", VK_NUMLOCK },
374 {
"SCLK", VK_SCROLL },
375 {
"RTSH", VK_RSHIFT },
376 {
"LCTL", VK_LCONTROL },
377 {
"AC10", VK_OEM_1 },
378 {
"AE12", VK_OEM_PLUS },
379 {
"AB08", VK_OEM_COMMA },
380 {
"AE11", VK_OEM_MINUS },
381 {
"AB09", VK_OEM_PERIOD },
382 {
"TLDE", VK_OEM_3 },
383 {
"AB11", VK_ABNT_C1 },
384 {
"I129", VK_ABNT_C2 },
385 {
"AD11", VK_OEM_4 },
386 {
"BKSL", VK_OEM_5 },
387 {
"AD12", VK_OEM_6 },
388 {
"AC11", VK_OEM_7 },
389 {
"LSGT", VK_OEM_102 },
390 {
"KPEN", VK_RETURN | KBDEXT },
391 {
"PAUS", VK_PAUSE | KBDEXT },
392 {
"PGUP", VK_PRIOR | KBDEXT },
393 {
"PGDN", VK_NEXT | KBDEXT },
394 {
"END", VK_END | KBDEXT },
395 {
"HOME", VK_HOME | KBDEXT },
396 {
"LEFT", VK_LEFT | KBDEXT },
397 {
"UP", VK_UP | KBDEXT },
398 {
"RGHT", VK_RIGHT | KBDEXT },
399 {
"DOWN", VK_DOWN | KBDEXT },
400 {
"PRSC", VK_SNAPSHOT | KBDEXT },
401 {
"INS", VK_INSERT | KBDEXT },
402 {
"DELE", VK_DELETE | KBDEXT },
403 {
"LWIN", VK_LWIN | KBDEXT },
404 {
"RWIN", VK_RWIN | KBDEXT },
405 {
"COMP", VK_APPS | KBDEXT },
406 {
"KPDV", VK_DIVIDE | KBDEXT },
407 {
"RCTL", VK_RCONTROL | KBDEXT },
408 {
"RALT", VK_RMENU | KBDEXT },
412 {
"HENK", VK_CONVERT },
413 {
"MUHE", VK_NONCONVERT },
420 const char* GetVirtualKeyName(DWORD vkcode)
422 const char* vkname = NULL;
424 if (vkcode < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE))
425 vkname = VIRTUAL_KEY_CODE_TABLE[vkcode].name;
433 DWORD GetVirtualKeyCodeFromName(
const char* vkname)
435 for (
size_t i = 0; i < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE); i++)
437 if (VIRTUAL_KEY_CODE_TABLE[i].name)
439 if (strcmp(vkname, VIRTUAL_KEY_CODE_TABLE[i].name) == 0)
440 return VIRTUAL_KEY_CODE_TABLE[i].code;
447 DWORD GetVirtualKeyCodeFromXkbKeyName(
const char* xkbname)
449 for (
size_t i = 0; i < ARRAYSIZE(XKB_KEYNAME_TABLE); i++)
451 if (XKB_KEYNAME_TABLE[i].name)
453 if (strcmp(xkbname, XKB_KEYNAME_TABLE[i].name) == 0)
454 return XKB_KEYNAME_TABLE[i].vkcode;