diff --git a/client/DirectFB/CMakeLists.txt b/client/DirectFB/CMakeLists.txt index 52c07ef69..061b05c54 100644 --- a/client/DirectFB/CMakeLists.txt +++ b/client/DirectFB/CMakeLists.txt @@ -37,6 +37,11 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} MODULE freerdp MODULES freerdp-core freerdp-gdi freerdp-locale freerdp-codec freerdp-primitives freerdp-utils) + +set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS + MONOLITHIC ${MONOLITHIC_BUILD} + MODULE winpr + MODULES winpr-input winpr-crt) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/client/DirectFB/df_event.c b/client/DirectFB/df_event.c index 68d8d72cd..5ec8b9635 100644 --- a/client/DirectFB/df_event.c +++ b/client/DirectFB/df_event.c @@ -17,6 +17,9 @@ * limitations under the License. */ +#include +#include + #include #include "df_event.h" @@ -26,7 +29,7 @@ static BYTE functionmap[128]; void df_keyboard_init() { - memset(keymap, 0, sizeof(keymap)); + ZeroMemory(keymap, sizeof(keymap)); /* Map DirectFB keycodes to Virtual Key Codes */ @@ -146,8 +149,7 @@ void df_keyboard_init() keymap[DIKI_META_R - DIKI_UNKNOWN] = VK_RWIN; keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = VK_APPS; - - memset(functionmap, 0, sizeof(functionmap)); + ZeroMemory(functionmap, sizeof(functionmap)); functionmap[DFB_FUNCTION_KEY(23) - DFB_FUNCTION_KEY(0)] = VK_HANGUL; functionmap[DFB_FUNCTION_KEY(24) - DFB_FUNCTION_KEY(0)] = VK_HANJA; @@ -190,19 +192,19 @@ void df_send_mouse_wheel_event(rdpInput* input, INT16 axisrel, UINT16 x, UINT16 void df_send_keyboard_event(rdpInput* input, BOOL down, BYTE keycode, BYTE function) { - BYTE vkcode; - RDP_SCANCODE rdp_scancode; - + DWORD scancode = 0; + BYTE vkcode = VK_NONE; + if (keycode) vkcode = keymap[keycode]; else if (function) vkcode = functionmap[function]; - else - return; - rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_virtual_key_code(vkcode); + if (vkcode != VK_NONE) + scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, input->context->settings->KeyboardType); - freerdp_input_send_keyboard_event_ex(input, down, rdp_scancode); + if (scancode) + freerdp_input_send_keyboard_event_ex(input, down, scancode); } BOOL df_event_process(freerdp* instance, DFBEvent* event) diff --git a/include/freerdp/locale/keyboard.h b/include/freerdp/locale/keyboard.h index c7a915140..1ba6e2158 100644 --- a/include/freerdp/locale/keyboard.h +++ b/include/freerdp/locale/keyboard.h @@ -20,10 +20,11 @@ #ifndef FREERDP_LOCALE_KEYBOARD_H #define FREERDP_LOCALE_KEYBOARD_H +#include + #include #include #include -#include #define RDP_KEYBOARD_LAYOUT_TYPE_STANDARD 1 #define RDP_KEYBOARD_LAYOUT_TYPE_VARIANT 2 @@ -203,6 +204,5 @@ FREERDP_API RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types); FREERDP_API const char* freerdp_keyboard_get_layout_name_from_id(UINT32 keyboardLayoutId); FREERDP_API RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode); FREERDP_API UINT32 freerdp_keyboard_get_x11_keycode_from_rdp_scancode(UINT32 scancode, BOOL extended); -FREERDP_API RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_virtual_key_code(UINT32 vkcode); #endif /* FREERDP_LOCALE_KEYBOARD_H */ diff --git a/include/freerdp/locale/vkcodes.h b/include/freerdp/locale/vkcodes.h deleted file mode 100644 index ca8d008be..000000000 --- a/include/freerdp/locale/vkcodes.h +++ /dev/null @@ -1,309 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Microsoft Windows Virtual-Key Codes - * - * Copyright 2009-2012 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_VIRTUAL_KEY_CODES_H -#define FREERDP_VIRTUAL_KEY_CODES_H - -#include -#include - -/* Virtual-Key Codes, @msdn{dd375731} */ - -/* Mouse buttons */ - -#define VK_LBUTTON 0x01 /* Left mouse button */ -#define VK_RBUTTON 0x02 /* Right mouse button */ -#define VK_CANCEL 0x03 /* Control-break processing */ -#define VK_MBUTTON 0x04 /* Middle mouse button (three-button mouse) */ -#define VK_XBUTTON1 0x05 /* Windows 2000/XP: X1 mouse button */ -#define VK_XBUTTON2 0x06 /* Windows 2000/XP: X2 mouse button */ - -/* 0x07 is undefined */ - -#define VK_BACK 0x08 /* BACKSPACE key */ -#define VK_TAB 0x09 /* TAB key */ - -/* 0x0A to 0x0B are reserved */ - -#define VK_CLEAR 0x0C /* CLEAR key */ -#define VK_RETURN 0x0D /* ENTER key */ - -/* 0x0E to 0x0F are undefined */ - -#define VK_SHIFT 0x10 /* SHIFT key */ -#define VK_CONTROL 0x11 /* CTRL key */ -#define VK_MENU 0x12 /* ALT key */ -#define VK_PAUSE 0x13 /* PAUSE key */ -#define VK_CAPITAL 0x14 /* CAPS LOCK key */ -#define VK_KANA 0x15 /* Input Method Editor (IME) Kana mode */ -#define VK_HANGUEL 0x15 /* IME Hanguel mode (maintained for compatibility; use #define VK_HANGUL) */ -#define VK_HANGUL 0x15 /* IME Hangul mode */ - -/* 0x16 is undefined */ - -#define VK_JUNJA 0x17 /* IME Junja mode */ -#define VK_FINAL 0x18 /* IME final mode */ -#define VK_HANJA 0x19 /* IME Hanja mode */ -#define VK_KANJI 0x19 /* IME Kanji mode */ - -/* 0x1A is undefined */ - -#define VK_ESCAPE 0x1B /* ESC key */ -#define VK_CONVERT 0x1C /* IME convert */ -#define VK_NONCONVERT 0x1D /* IME nonconvert */ -#define VK_ACCEPT 0x1E /* IME accept */ -#define VK_MODECHANGE 0x1F /* IME mode change request */ - -#define VK_SPACE 0x20 /* SPACEBAR */ -#define VK_PRIOR 0x21 /* PAGE UP key */ -#define VK_NEXT 0x22 /* PAGE DOWN key */ -#define VK_END 0x23 /* END key */ -#define VK_HOME 0x24 /* HOME key */ -#define VK_LEFT 0x25 /* LEFT ARROW key */ -#define VK_UP 0x26 /* UP ARROW key */ -#define VK_RIGHT 0x27 /* RIGHT ARROW key */ -#define VK_DOWN 0x28 /* DOWN ARROW key */ -#define VK_SELECT 0x29 /* SELECT key */ -#define VK_PRINT 0x2A /* PRINT key */ -#define VK_EXECUTE 0x2B /* EXECUTE key */ -#define VK_SNAPSHOT 0x2C /* PRINT SCREEN key */ -#define VK_INSERT 0x2D /* INS key */ -#define VK_DELETE 0x2E /* DEL key */ -#define VK_HELP 0x2F /* HELP key */ - -/* Digits, the last 4 bits of the code represent the corresponding digit */ - -#define VK_KEY_0 0x30 /* '0' key */ -#define VK_KEY_1 0x31 /* '1' key */ -#define VK_KEY_2 0x32 /* '2' key */ -#define VK_KEY_3 0x33 /* '3' key */ -#define VK_KEY_4 0x34 /* '4' key */ -#define VK_KEY_5 0x35 /* '5' key */ -#define VK_KEY_6 0x36 /* '6' key */ -#define VK_KEY_7 0x37 /* '7' key */ -#define VK_KEY_8 0x38 /* '8' key */ -#define VK_KEY_9 0x39 /* '9' key */ - -/* 0x3A to 0x40 are undefined */ - -/* The alphabet, the code corresponds to the capitalized letter in the ASCII code */ - -#define VK_KEY_A 0x41 /* 'A' key */ -#define VK_KEY_B 0x42 /* 'B' key */ -#define VK_KEY_C 0x43 /* 'C' key */ -#define VK_KEY_D 0x44 /* 'D' key */ -#define VK_KEY_E 0x45 /* 'E' key */ -#define VK_KEY_F 0x46 /* 'F' key */ -#define VK_KEY_G 0x47 /* 'G' key */ -#define VK_KEY_H 0x48 /* 'H' key */ -#define VK_KEY_I 0x49 /* 'I' key */ -#define VK_KEY_J 0x4A /* 'J' key */ -#define VK_KEY_K 0x4B /* 'K' key */ -#define VK_KEY_L 0x4C /* 'L' key */ -#define VK_KEY_M 0x4D /* 'M' key */ -#define VK_KEY_N 0x4E /* 'N' key */ -#define VK_KEY_O 0x4F /* 'O' key */ -#define VK_KEY_P 0x50 /* 'P' key */ -#define VK_KEY_Q 0x51 /* 'Q' key */ -#define VK_KEY_R 0x52 /* 'R' key */ -#define VK_KEY_S 0x53 /* 'S' key */ -#define VK_KEY_T 0x54 /* 'T' key */ -#define VK_KEY_U 0x55 /* 'U' key */ -#define VK_KEY_V 0x56 /* 'V' key */ -#define VK_KEY_W 0x57 /* 'W' key */ -#define VK_KEY_X 0x58 /* 'X' key */ -#define VK_KEY_Y 0x59 /* 'Y' key */ -#define VK_KEY_Z 0x5A /* 'Z' key */ - -#define VK_LWIN 0x5B /* Left Windows key (Microsoft Natural keyboard) */ -#define VK_RWIN 0x5C /* Right Windows key (Natural keyboard) */ -#define VK_APPS 0x5D /* Applications key (Natural keyboard) */ - -/* 0x5E is reserved */ - -#define VK_SLEEP 0x5F /* Computer Sleep key */ - -/* Numeric keypad digits, the last four bits of the code represent the corresponding digit */ - -#define VK_NUMPAD0 0x60 /* Numeric keypad '0' key */ -#define VK_NUMPAD1 0x61 /* Numeric keypad '1' key */ -#define VK_NUMPAD2 0x62 /* Numeric keypad '2' key */ -#define VK_NUMPAD3 0x63 /* Numeric keypad '3' key */ -#define VK_NUMPAD4 0x64 /* Numeric keypad '4' key */ -#define VK_NUMPAD5 0x65 /* Numeric keypad '5' key */ -#define VK_NUMPAD6 0x66 /* Numeric keypad '6' key */ -#define VK_NUMPAD7 0x67 /* Numeric keypad '7' key */ -#define VK_NUMPAD8 0x68 /* Numeric keypad '8' key */ -#define VK_NUMPAD9 0x69 /* Numeric keypad '9' key */ - -/* Numeric keypad operators and special keys */ - -#define VK_MULTIPLY 0x6A /* Multiply key */ -#define VK_ADD 0x6B /* Add key */ -#define VK_SEPARATOR 0x6C /* Separator key */ -#define VK_SUBTRACT 0x6D /* Subtract key */ -#define VK_DECIMAL 0x6E /* Decimal key */ -#define VK_DIVIDE 0x6F /* Divide key */ - -/* Function keys, from F1 to F24 */ - -#define VK_F1 0x70 /* F1 key */ -#define VK_F2 0x71 /* F2 key */ -#define VK_F3 0x72 /* F3 key */ -#define VK_F4 0x73 /* F4 key */ -#define VK_F5 0x74 /* F5 key */ -#define VK_F6 0x75 /* F6 key */ -#define VK_F7 0x76 /* F7 key */ -#define VK_F8 0x77 /* F8 key */ -#define VK_F9 0x78 /* F9 key */ -#define VK_F10 0x79 /* F10 key */ -#define VK_F11 0x7A /* F11 key */ -#define VK_F12 0x7B /* F12 key */ -#define VK_F13 0x7C /* F13 key */ -#define VK_F14 0x7D /* F14 key */ -#define VK_F15 0x7E /* F15 key */ -#define VK_F16 0x7F /* F16 key */ -#define VK_F17 0x80 /* F17 key */ -#define VK_F18 0x81 /* F18 key */ -#define VK_F19 0x82 /* F19 key */ -#define VK_F20 0x83 /* F20 key */ -#define VK_F21 0x84 /* F21 key */ -#define VK_F22 0x85 /* F22 key */ -#define VK_F23 0x86 /* F23 key */ -#define VK_F24 0x87 /* F24 key */ - -/* 0x88 to 0x8F are unassigned */ - -#define VK_NUMLOCK 0x90 /* NUM LOCK key */ -#define VK_SCROLL 0x91 /* SCROLL LOCK key */ - -/* 0x92 to 0x96 are OEM specific */ -/* 0x97 to 0x9F are unassigned */ - -/* Modifier keys */ - -#define VK_LSHIFT 0xA0 /* Left SHIFT key */ -#define VK_RSHIFT 0xA1 /* Right SHIFT key */ -#define VK_LCONTROL 0xA2 /* Left CONTROL key */ -#define VK_RCONTROL 0xA3 /* Right CONTROL key */ -#define VK_LMENU 0xA4 /* Left MENU key */ -#define VK_RMENU 0xA5 /* Right MENU key */ - -/* Browser related keys */ - -#define VK_BROWSER_BACK 0xA6 /* Windows 2000/XP: Browser Back key */ -#define VK_BROWSER_FORWARD 0xA7 /* Windows 2000/XP: Browser Forward key */ -#define VK_BROWSER_REFRESH 0xA8 /* Windows 2000/XP: Browser Refresh key */ -#define VK_BROWSER_STOP 0xA9 /* Windows 2000/XP: Browser Stop key */ -#define VK_BROWSER_SEARCH 0xAA /* Windows 2000/XP: Browser Search key */ -#define VK_BROWSER_FAVORITES 0xAB /* Windows 2000/XP: Browser Favorites key */ -#define VK_BROWSER_HOME 0xAC /* Windows 2000/XP: Browser Start and Home key */ - -/* Volume related keys */ - -#define VK_VOLUME_MUTE 0xAD /* Windows 2000/XP: Volume Mute key */ -#define VK_VOLUME_DOWN 0xAE /* Windows 2000/XP: Volume Down key */ -#define VK_VOLUME_UP 0xAF /* Windows 2000/XP: Volume Up key */ - -/* Media player related keys */ - -#define VK_MEDIA_NEXT_TRACK 0xB0 /* Windows 2000/XP: Next Track key */ -#define VK_MEDIA_PREV_TRACK 0xB1 /* Windows 2000/XP: Previous Track key */ -#define VK_MEDIA_STOP 0xB2 /* Windows 2000/XP: Stop Media key */ -#define VK_MEDIA_PLAY_PAUSE 0xB3 /* Windows 2000/XP: Play/Pause Media key */ - -/* Application launcher keys */ - -#define VK_LAUNCH_MAIL 0xB4 /* Windows 2000/XP: Start Mail key */ -#define VK_MEDIA_SELECT 0xB5 /* Windows 2000/XP: Select Media key */ -#define VK_LAUNCH_APP1 0xB6 /* Windows 2000/XP: Start Application 1 key */ -#define VK_LAUNCH_APP2 0xB7 /* Windows 2000/XP: Start Application 2 key */ - -/* 0xB8 and 0xB9 are reserved */ - -/* OEM keys */ - -#define VK_OEM_1 0xBA /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the ';:' key */ - -#define VK_OEM_PLUS 0xBB /* Windows 2000/XP: For any country/region, the '+' key */ -#define VK_OEM_COMMA 0xBC /* Windows 2000/XP: For any country/region, the ',' key */ -#define VK_OEM_MINUS 0xBD /* Windows 2000/XP: For any country/region, the '-' key */ -#define VK_OEM_PERIOD 0xBE /* Windows 2000/XP: For any country/region, the '.' key */ - -#define VK_OEM_2 0xBF /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the '/?' key */ - -#define VK_OEM_3 0xC0 /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the '`~' key */ - -/* 0xC1 to 0xD7 are reserved */ -#define VK_ABNT_C1 0xC1 /* Brazilian (ABNT) Keyboard */ -#define VK_ABNT_C2 0xC2 /* Brazilian (ABNT) Keyboard */ - -/* 0xD8 to 0xDA are unassigned */ - -#define VK_OEM_4 0xDB /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the '[{' key */ - -#define VK_OEM_5 0xDC /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the '\|' key */ - -#define VK_OEM_6 0xDD /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the ']}' key */ - -#define VK_OEM_7 0xDE /* Used for miscellaneous characters; it can vary by keyboard. */ - /* Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key */ - -#define VK_OEM_8 0xDF /* Used for miscellaneous characters; it can vary by keyboard. */ - -/* 0xE0 is reserved */ -/* 0xE1 is OEM specific */ - -#define VK_OEM_102 0xE2 /* Windows 2000/XP: Either the angle bracket key or */ - /* the backslash key on the RT 102-key keyboard */ - -/* 0xE3 and 0xE4 are OEM specific */ - -#define VK_PROCESSKEY 0xE5 /* Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key */ - -/* 0xE6 is OEM specific */ - -#define VK_PACKET 0xE7 /* Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. */ - /* The #define VK_PACKET key is the low word of a 32-bit Virtual Key value used */ - /* for non-keyboard input methods. For more information, */ - /* see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP */ - -/* 0xE8 is unassigned */ -/* 0xE9 to 0xF5 are OEM specific */ - -#define VK_ATTN 0xF6 /* Attn key */ -#define VK_CRSEL 0xF7 /* CrSel key */ -#define VK_EXSEL 0xF8 /* ExSel key */ -#define VK_EREOF 0xF9 /* Erase EOF key */ -#define VK_PLAY 0xFA /* Play key */ -#define VK_ZOOM 0xFB /* Zoom key */ -#define VK_NONAME 0xFC /* Reserved */ -#define VK_PA1 0xFD /* PA1 key */ -#define VK_OEM_CLEAR 0xFE /* Clear key */ - -FREERDP_API const char* freerdp_keyboard_get_virtual_key_code_name(UINT32 vkcode); -FREERDP_API UINT32 freerdp_keyboard_get_virtual_key_code_from_name(const char* vkcode_name); - -#endif /* FREERDP_VIRTUAL_KEY_CODES_H */ diff --git a/include/freerdp/scancode.h b/include/freerdp/scancode.h index cb24784de..88f893a0b 100644 --- a/include/freerdp/scancode.h +++ b/include/freerdp/scancode.h @@ -20,6 +20,8 @@ #ifndef FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H #define FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H +#include + /* @msdn{cc240584} says: * "... (a scancode is an 8-bit value specifying a key location on the keyboard). * The server accepts a scancode value and translates it into the correct character depending on the language locale and keyboard layout used in the session." @@ -29,8 +31,8 @@ typedef UINT32 RDP_SCANCODE; /* Our own representation of a RDP protocol scancode */ #define RDP_SCANCODE_CODE(_rdp_scancode) ((BYTE)(_rdp_scancode & 0xFF)) -#define RDP_SCANCODE_EXTENDED(_rdp_scancode) (((_rdp_scancode) & 0x100) ? TRUE : FALSE) -#define MAKE_RDP_SCANCODE(_code, _extended) (((_code) & 0xFF) | ((_extended) ? 0x100 : 0)) +#define RDP_SCANCODE_EXTENDED(_rdp_scancode) (((_rdp_scancode) & KBDEXT) ? TRUE : FALSE) +#define MAKE_RDP_SCANCODE(_code, _extended) (((_code) & 0xFF) | ((_extended) ? KBDEXT : 0)) /* Defines for known RDP_SCANCODE protocol values. * Mostly the same as the PKBDLLHOOKSTRUCT scanCode, "A hardware scan code for the key", @msdn{ms644967}. diff --git a/libfreerdp/locale/CMakeLists.txt b/libfreerdp/locale/CMakeLists.txt index bb480f7ea..e89dac395 100644 --- a/libfreerdp/locale/CMakeLists.txt +++ b/libfreerdp/locale/CMakeLists.txt @@ -19,7 +19,6 @@ set(MODULE_NAME "freerdp-locale") set(MODULE_PREFIX "FREERDP_LOCALE") set(${MODULE_PREFIX}_SRCS - virtual_key_codes.c keyboard_layout.c keyboard.c locale.c @@ -87,7 +86,7 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} MODULE winpr - MODULES winpr-crt) + MODULES winpr-input winpr-crt) if(MONOLITHIC_BUILD) set(FREERDP_LIBS ${FREERDP_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE) diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c index 4dd5cf6c5..aca2666fc 100644 --- a/libfreerdp/locale/keyboard.c +++ b/libfreerdp/locale/keyboard.c @@ -44,8 +44,6 @@ UINT32 RDP_SCANCODE_TO_X11_KEYCODE[256][2]; RDP_SCANCODE X11_KEYCODE_TO_RDP_SCANCODE[256]; -extern const RDP_SCANCODE VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[256]; - UINT32 freerdp_detect_keyboard(UINT32 keyboardLayoutID) { if (keyboardLayoutID != 0) @@ -81,11 +79,14 @@ UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId) #endif keyboardLayoutId = freerdp_detect_keyboard(keyboardLayoutId); - memset(RDP_SCANCODE_TO_X11_KEYCODE, 0, sizeof(RDP_SCANCODE_TO_X11_KEYCODE)); - for (keycode=0; keycode < ARRAYSIZE(RDP_SCANCODE_TO_X11_KEYCODE); keycode++) + ZeroMemory(RDP_SCANCODE_TO_X11_KEYCODE, sizeof(RDP_SCANCODE_TO_X11_KEYCODE)); + + for (keycode = 0; keycode < ARRAYSIZE(RDP_SCANCODE_TO_X11_KEYCODE); keycode++) + { RDP_SCANCODE_TO_X11_KEYCODE [RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode])] [RDP_SCANCODE_EXTENDED(X11_KEYCODE_TO_RDP_SCANCODE[keycode]) ? 1 : 0] = keycode; + } return keyboardLayoutId; } @@ -106,8 +107,3 @@ UINT32 freerdp_keyboard_get_x11_keycode_from_rdp_scancode(UINT32 scancode, BOOL else return RDP_SCANCODE_TO_X11_KEYCODE[scancode][0]; } - -RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_virtual_key_code(UINT32 vkcode) -{ - return VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[vkcode]; -} diff --git a/libfreerdp/locale/keyboard_layout.c b/libfreerdp/locale/keyboard_layout.c index 7ab045b74..f84f6fe87 100644 --- a/libfreerdp/locale/keyboard_layout.c +++ b/libfreerdp/locale/keyboard_layout.c @@ -214,269 +214,6 @@ static const RDP_KEYBOARD_IME RDP_KEYBOARD_IME_TABLE[] = { KBD_CHINESE_TRADITIONAL_ALPHANUMERIC, "romanime.ime", "Chinese (Traditional) - Alphanumeric" } }; - -/* the index in this table is the virtual key code */ - -const RDP_SCANCODE VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[256] = -{ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_LBUTTON */ - RDP_SCANCODE_UNKNOWN, /* VK_RBUTTON */ - RDP_SCANCODE_UNKNOWN, /* VK_CANCEL */ - RDP_SCANCODE_UNKNOWN, /* VK_MBUTTON */ - RDP_SCANCODE_UNKNOWN, /* VK_XBUTTON1 */ - RDP_SCANCODE_UNKNOWN, /* VK_XBUTTON2 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_BACKSPACE, /* VK_BACK */ - RDP_SCANCODE_TAB, /* VK_TAB */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_CLEAR */ - RDP_SCANCODE_RETURN, /* VK_RETURN */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_LSHIFT, /* VK_SHIFT */ - RDP_SCANCODE_UNKNOWN, /* VK_CONTROL */ - RDP_SCANCODE_LMENU, /* VK_MENU */ - RDP_SCANCODE_PAUSE, /* VK_PAUSE */ - RDP_SCANCODE_CAPSLOCK, /* VK_CAPITAL */ - RDP_SCANCODE_UNKNOWN, /* VK_KANA / VK_HANGUL */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_JUNJA */ - RDP_SCANCODE_UNKNOWN, /* VK_FINAL */ - RDP_SCANCODE_UNKNOWN, /* VK_HANJA / VK_KANJI */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_ESCAPE, /* VK_ESCAPE */ - RDP_SCANCODE_UNKNOWN, /* VK_CONVERT */ - RDP_SCANCODE_UNKNOWN, /* VK_NONCONVERT */ - RDP_SCANCODE_UNKNOWN, /* VK_ACCEPT */ - RDP_SCANCODE_UNKNOWN, /* VK_MODECHANGE */ - RDP_SCANCODE_SPACE, /* VK_SPACE */ - RDP_SCANCODE_PRIOR, /* VK_PRIOR */ - RDP_SCANCODE_NEXT, /* VK_NEXT */ - RDP_SCANCODE_END, /* VK_END */ - RDP_SCANCODE_HOME, /* VK_HOME */ - RDP_SCANCODE_LEFT, /* VK_LEFT */ - RDP_SCANCODE_UP, /* VK_UP */ - RDP_SCANCODE_RIGHT, /* VK_RIGHT */ - RDP_SCANCODE_DOWN, /* VK_DOWN */ - RDP_SCANCODE_UNKNOWN, /* VK_SELECT */ - RDP_SCANCODE_PRINTSCREEN,/* VK_PRINT */ - RDP_SCANCODE_PRINTSCREEN,/* VK_EXECUTE */ - RDP_SCANCODE_PRINTSCREEN,/* VK_SNAPSHOT */ - RDP_SCANCODE_INSERT, /* VK_INSERT */ - RDP_SCANCODE_DELETE, /* VK_DELETE */ - RDP_SCANCODE_HELP, /* VK_HELP */ - RDP_SCANCODE_KEY_0, /* VK_KEY_0 */ - RDP_SCANCODE_KEY_1, /* VK_KEY_1 */ - RDP_SCANCODE_KEY_2, /* VK_KEY_2 */ - RDP_SCANCODE_KEY_3, /* VK_KEY_3 */ - RDP_SCANCODE_KEY_4, /* VK_KEY_4 */ - RDP_SCANCODE_KEY_5, /* VK_KEY_5 */ - RDP_SCANCODE_KEY_6, /* VK_KEY_6 */ - RDP_SCANCODE_KEY_7, /* VK_KEY_7 */ - RDP_SCANCODE_KEY_8, /* VK_KEY_8 */ - RDP_SCANCODE_KEY_9, /* VK_KEY_9 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_KEY_A, /* VK_KEY_A */ - RDP_SCANCODE_KEY_B, /* VK_KEY_B */ - RDP_SCANCODE_KEY_C, /* VK_KEY_C */ - RDP_SCANCODE_KEY_D, /* VK_KEY_D */ - RDP_SCANCODE_KEY_E, /* VK_KEY_E */ - RDP_SCANCODE_KEY_F, /* VK_KEY_F */ - RDP_SCANCODE_KEY_G, /* VK_KEY_G */ - RDP_SCANCODE_KEY_H, /* VK_KEY_H */ - RDP_SCANCODE_KEY_I, /* VK_KEY_I */ - RDP_SCANCODE_KEY_J, /* VK_KEY_J */ - RDP_SCANCODE_KEY_K, /* VK_KEY_K */ - RDP_SCANCODE_KEY_L, /* VK_KEY_L */ - RDP_SCANCODE_KEY_M, /* VK_KEY_M */ - RDP_SCANCODE_KEY_N, /* VK_KEY_N */ - RDP_SCANCODE_KEY_O, /* VK_KEY_O */ - RDP_SCANCODE_KEY_P, /* VK_KEY_P */ - RDP_SCANCODE_KEY_Q, /* VK_KEY_Q */ - RDP_SCANCODE_KEY_R, /* VK_KEY_R */ - RDP_SCANCODE_KEY_S, /* VK_KEY_S */ - RDP_SCANCODE_KEY_T, /* VK_KEY_T */ - RDP_SCANCODE_KEY_U, /* VK_KEY_U */ - RDP_SCANCODE_KEY_V, /* VK_KEY_V */ - RDP_SCANCODE_KEY_W, /* VK_KEY_W */ - RDP_SCANCODE_KEY_X, /* VK_KEY_X */ - RDP_SCANCODE_KEY_Y, /* VK_KEY_Y */ - RDP_SCANCODE_KEY_Z, /* VK_KEY_Z */ - RDP_SCANCODE_LWIN, /* VK_LWIN */ - RDP_SCANCODE_RWIN, /* VK_RWIN */ - RDP_SCANCODE_APPS, /* VK_APPS */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_SLEEP, /* VK_SLEEP */ - RDP_SCANCODE_NUMPAD0, /* VK_NUMPAD0 */ - RDP_SCANCODE_NUMPAD1, /* VK_NUMPAD1 */ - RDP_SCANCODE_NUMPAD2, /* VK_NUMPAD2 */ - RDP_SCANCODE_NUMPAD3, /* VK_NUMPAD3 */ - RDP_SCANCODE_NUMPAD4, /* VK_NUMPAD4 */ - RDP_SCANCODE_NUMPAD5, /* VK_NUMPAD5 */ - RDP_SCANCODE_NUMPAD6, /* VK_NUMPAD6 */ - RDP_SCANCODE_NUMPAD7, /* VK_NUMPAD7 */ - RDP_SCANCODE_NUMPAD8, /* VK_NUMPAD8 */ - RDP_SCANCODE_NUMPAD9, /* VK_NUMPAD9 */ - RDP_SCANCODE_MULTIPLY, /* VK_MULTIPLY */ - RDP_SCANCODE_ADD, /* VK_ADD */ - RDP_SCANCODE_UNKNOWN, /* VK_SEPARATOR */ - RDP_SCANCODE_SUBTRACT, /* VK_SUBTRACT */ - RDP_SCANCODE_DECIMAL, /* VK_DECIMAL */ - RDP_SCANCODE_DIVIDE, /* VK_DIVIDE */ - RDP_SCANCODE_F1, /* VK_F1 */ - RDP_SCANCODE_F2, /* VK_F2 */ - RDP_SCANCODE_F3, /* VK_F3 */ - RDP_SCANCODE_F4, /* VK_F4 */ - RDP_SCANCODE_F5, /* VK_F5 */ - RDP_SCANCODE_F6, /* VK_F6 */ - RDP_SCANCODE_F7, /* VK_F7 */ - RDP_SCANCODE_F8, /* VK_F8 */ - RDP_SCANCODE_F9, /* VK_F9 */ - RDP_SCANCODE_F10, /* VK_F10 */ - RDP_SCANCODE_F11, /* VK_F11 */ - RDP_SCANCODE_F12, /* VK_F12 */ - RDP_SCANCODE_F13, /* VK_F13 */ - RDP_SCANCODE_F14, /* VK_F14 */ - RDP_SCANCODE_F15, /* VK_F15 */ - RDP_SCANCODE_F16, /* VK_F16 */ - RDP_SCANCODE_F17, /* VK_F17 */ - RDP_SCANCODE_F18, /* VK_F18 */ - RDP_SCANCODE_F19, /* VK_F19 */ - RDP_SCANCODE_F20, /* VK_F20 */ - RDP_SCANCODE_F21, /* VK_F21 */ - RDP_SCANCODE_F22, /* VK_F22 */ - RDP_SCANCODE_F23, /* VK_F23 */ - RDP_SCANCODE_F24, /* VK_F24 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_NUMLOCK, /* VK_NUMLOCK */ - RDP_SCANCODE_SCROLLLOCK, /* VK_SCROLL */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_LSHIFT, /* VK_LSHIFT */ - RDP_SCANCODE_RSHIFT, /* VK_RSHIFT */ - RDP_SCANCODE_LCONTROL, /* VK_LCONTROL */ - RDP_SCANCODE_RCONTROL, /* VK_RCONTROL */ - RDP_SCANCODE_LMENU, /* VK_LMENU */ - RDP_SCANCODE_RMENU, /* VK_RMENU */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_BACK */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_FORWARD */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_REFRESH */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_STOP */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_SEARCH */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_FAVORITES */ - RDP_SCANCODE_UNKNOWN, /* VK_BROWSER_HOME */ - RDP_SCANCODE_UNKNOWN, /* VK_VOLUME_MUTE */ - RDP_SCANCODE_UNKNOWN, /* VK_VOLUME_DOWN */ - RDP_SCANCODE_UNKNOWN, /* VK_VOLUME_UP */ - RDP_SCANCODE_UNKNOWN, /* VK_MEDIA_NEXT_TRACK */ - RDP_SCANCODE_UNKNOWN, /* VK_MEDIA_PREV_TRACK */ - RDP_SCANCODE_UNKNOWN, /* VK_MEDIA_STOP */ - RDP_SCANCODE_UNKNOWN, /* VK_MEDIA_PLAY_PAUSE */ - RDP_SCANCODE_UNKNOWN, /* VK_LAUNCH_MAIL */ - RDP_SCANCODE_UNKNOWN, /* VK_MEDIA_SELECT */ - RDP_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP1 */ - RDP_SCANCODE_UNKNOWN, /* VK_LAUNCH_APP2 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_OEM_1, /* VK_OEM_1 */ - RDP_SCANCODE_OEM_PLUS, /* VK_OEM_PLUS */ - RDP_SCANCODE_OEM_COMMA, /* VK_OEM_COMMA */ - RDP_SCANCODE_OEM_MINUS, /* VK_OEM_MINUS */ - RDP_SCANCODE_OEM_PERIOD, /* VK_OEM_PERIOD */ - RDP_SCANCODE_OEM_2, /* VK_OEM_2 */ - RDP_SCANCODE_OEM_3, /* VK_OEM_3 */ - RDP_SCANCODE_ABNT_C1, /* VK_ABNT_C1 */ - RDP_SCANCODE_ABNT_C2, /* VK_ABNT_C2 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_OEM_4, /* VK_OEM_4 */ - RDP_SCANCODE_OEM_5, /* VK_OEM_5 */ - RDP_SCANCODE_OEM_6, /* VK_OEM_6 */ - RDP_SCANCODE_OEM_7, /* VK_OEM_7 */ - RDP_SCANCODE_LCONTROL, /* VK_OEM_8 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_OEM_102, /* VK_OEM_102 */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_PROCESSKEY */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_PACKET */ - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, - RDP_SCANCODE_UNKNOWN, /* VK_ATTN */ - RDP_SCANCODE_UNKNOWN, /* VK_CRSEL */ - RDP_SCANCODE_UNKNOWN, /* VK_EXSEL */ - RDP_SCANCODE_UNKNOWN, /* VK_EREOF */ - RDP_SCANCODE_UNKNOWN, /* VK_PLAY */ - RDP_SCANCODE_ZOOM, /* VK_ZOOM */ - RDP_SCANCODE_UNKNOWN, /* VK_NONAME */ - RDP_SCANCODE_UNKNOWN, /* VK_PA1 */ - RDP_SCANCODE_UNKNOWN, /* VK_OEM_CLEAR */ - RDP_SCANCODE_UNKNOWN -}; - RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types) { int num, length, i; diff --git a/libfreerdp/locale/keyboard_x11.c b/libfreerdp/locale/keyboard_x11.c index fe5adc254..d94d6176e 100644 --- a/libfreerdp/locale/keyboard_x11.c +++ b/libfreerdp/locale/keyboard_x11.c @@ -39,10 +39,6 @@ #include "keyboard_sun.h" #endif - -extern const RDP_SCANCODE VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[256]; - - UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_variant) { char* pch; @@ -67,9 +63,9 @@ UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_var * "multi" the keyboard layout variant */ - while(fgets(buffer, sizeof(buffer), xprop) != NULL) + while (fgets(buffer, sizeof(buffer), xprop) != NULL) { - if((pch = strstr(buffer, "_XKB_RULES_NAMES_BACKUP(STRING) = ")) != NULL) + if ((pch = strstr(buffer, "_XKB_RULES_NAMES_BACKUP(STRING) = ")) != NULL) { /* "rules" */ pch = strchr(&buffer[34], ','); // We assume it is xorg @@ -113,9 +109,9 @@ UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_var xprop = popen("xprop -root _XKB_RULES_NAMES", "r"); - while(fgets(buffer, sizeof(buffer), xprop) != NULL) + while (fgets(buffer, sizeof(buffer), xprop) != NULL) { - if((pch = strstr(buffer, "_XKB_RULES_NAMES(STRING) = ")) != NULL) + if ((pch = strstr(buffer, "_XKB_RULES_NAMES(STRING) = ")) != NULL) { /* "rules" */ pch = strchr(&buffer[27], ','); // We assume it is xorg @@ -211,7 +207,7 @@ char* freerdp_detect_keymap_from_xkb() #ifdef __APPLE__ -const UINT32 KEYCODE_TO_VKCODE_MACOSX[256] = +const DWORD KEYCODE_TO_VKCODE_MACOSX[256] = { 0, /* 0 */ 0, /* 1 */ @@ -503,16 +499,17 @@ UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keyco if (keyboardLayoutId == 0) { keyboardLayoutId = freerdp_detect_keyboard_layout_from_xkb(&xkb_layout, &xkb_variant); + if (xkb_layout) free(xkb_layout); + if (xkb_variant) free(xkb_variant); - } keymap = freerdp_detect_keymap_from_xkb(); - if (keymap != NULL) + if (keymap) { freerdp_keyboard_load_maps(keycode_to_vkcode, keymap); free(keymap); @@ -520,15 +517,5 @@ UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keyco } #endif - for (keycode = 0; keycode < 256; keycode++) - { - vkcode = keycode_to_vkcode[keycode]; - - if (!(vkcode > 0 && vkcode < 256)) - continue; - - x11_keycode_to_rdp_scancode[keycode] = VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[vkcode]; - } - return keyboardLayoutId; } diff --git a/libfreerdp/locale/keyboard_xkbfile.c b/libfreerdp/locale/keyboard_xkbfile.c index 1b15be6ea..e0efb22fd 100644 --- a/libfreerdp/locale/keyboard_xkbfile.c +++ b/libfreerdp/locale/keyboard_xkbfile.c @@ -286,14 +286,15 @@ int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keyco for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { found = FALSE; - memcpy(xkb_keyname, xkb->names->keys[i].name, 4); + CopyMemory(xkb_keyname, xkb->names->keys[i].name, 4); if (strlen(xkb_keyname) < 1) continue; + printf("XKB KeyName: %s\n", xkb_keyname); + for (j = 0; j < ARRAYSIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++) { - if (!strcmp(xkb_keyname, XKB_KEY_NAME_SCANCODE_TABLE[j].xkb_keyname)) { DEBUG_KBD("%4s: keycode: 0x%02X -> rdp scancode: 0x%04X", diff --git a/libfreerdp/locale/virtual_key_codes.c b/libfreerdp/locale/virtual_key_codes.c deleted file mode 100644 index 7247f9872..000000000 --- a/libfreerdp/locale/virtual_key_codes.c +++ /dev/null @@ -1,318 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Keyboard Layouts - * - * Copyright 2009-2012 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include - -#include - -struct _VIRTUAL_KEY_CODE -{ - UINT32 code; /* Windows Virtual Key Code */ - const char* name; /* Virtual Key Code Name */ -}; -typedef struct _VIRTUAL_KEY_CODE VIRTUAL_KEY_CODE; - -static const VIRTUAL_KEY_CODE VIRTUAL_KEY_CODE_TABLE[256] = -{ - { 0, "" }, - { VK_LBUTTON, "VK_LBUTTON" }, - { VK_RBUTTON, "VK_RBUTTON" }, - { VK_CANCEL, "VK_CANCEL" }, - { VK_MBUTTON, "VK_MBUTTON" }, - { VK_XBUTTON1, "VK_XBUTTON1" }, - { VK_XBUTTON2, "VK_XBUTTON2" }, - { 0, "" }, - { VK_BACK, "VK_BACK" }, - { VK_TAB, "VK_TAB" }, - { 0, "" }, - { 0, "" }, - { VK_CLEAR, "VK_CLEAR" }, - { VK_RETURN, "VK_RETURN" }, - { 0, "" }, - { 0, "" }, - { VK_SHIFT, "VK_SHIFT" }, - { VK_CONTROL, "VK_CONTROL" }, - { VK_MENU, "VK_MENU" }, - { VK_PAUSE, "VK_PAUSE" }, - { VK_CAPITAL, "VK_CAPITAL" }, - { VK_KANA, "VK_KANA" }, /* also VK_HANGUL */ - { 0, "" }, - { VK_JUNJA, "VK_JUNJA" }, - { VK_FINAL, "VK_FINAL" }, - { VK_KANJI, "VK_KANJI" }, /* also VK_HANJA */ - { 0, "" }, - { VK_ESCAPE, "VK_ESCAPE" }, - { VK_CONVERT, "VK_CONVERT" }, - { VK_NONCONVERT, "VK_NONCONVERT" }, - { VK_ACCEPT, "VK_ACCEPT" }, - { VK_MODECHANGE, "VK_MODECHANGE" }, - { VK_SPACE, "VK_SPACE" }, - { VK_PRIOR, "VK_PRIOR" }, - { VK_NEXT, "VK_NEXT" }, - { VK_END, "VK_END" }, - { VK_HOME, "VK_HOME" }, - { VK_LEFT, "VK_LEFT" }, - { VK_UP, "VK_UP" }, - { VK_RIGHT, "VK_RIGHT" }, - { VK_DOWN, "VK_DOWN" }, - { VK_SELECT, "VK_SELECT" }, - { VK_PRINT, "VK_PRINT" }, - { VK_EXECUTE, "VK_EXECUTE" }, - { VK_SNAPSHOT, "VK_SNAPSHOT" }, - { VK_INSERT, "VK_INSERT" }, - { VK_DELETE, "VK_DELETE" }, - { VK_HELP, "VK_HELP" }, - { VK_KEY_0, "VK_KEY_0" }, - { VK_KEY_1, "VK_KEY_1" }, - { VK_KEY_2, "VK_KEY_2" }, - { VK_KEY_3, "VK_KEY_3" }, - { VK_KEY_4, "VK_KEY_4" }, - { VK_KEY_5, "VK_KEY_5" }, - { VK_KEY_6, "VK_KEY_6" }, - { VK_KEY_7, "VK_KEY_7" }, - { VK_KEY_8, "VK_KEY_8" }, - { VK_KEY_9, "VK_KEY_9" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { VK_KEY_A, "VK_KEY_A" }, - { VK_KEY_B, "VK_KEY_B" }, - { VK_KEY_C, "VK_KEY_C" }, - { VK_KEY_D, "VK_KEY_D" }, - { VK_KEY_E, "VK_KEY_E" }, - { VK_KEY_F, "VK_KEY_F" }, - { VK_KEY_G, "VK_KEY_G" }, - { VK_KEY_H, "VK_KEY_H" }, - { VK_KEY_I, "VK_KEY_I" }, - { VK_KEY_J, "VK_KEY_J" }, - { VK_KEY_K, "VK_KEY_K" }, - { VK_KEY_L, "VK_KEY_L" }, - { VK_KEY_M, "VK_KEY_M" }, - { VK_KEY_N, "VK_KEY_N" }, - { VK_KEY_O, "VK_KEY_O" }, - { VK_KEY_P, "VK_KEY_P" }, - { VK_KEY_Q, "VK_KEY_Q" }, - { VK_KEY_R, "VK_KEY_R" }, - { VK_KEY_S, "VK_KEY_S" }, - { VK_KEY_T, "VK_KEY_T" }, - { VK_KEY_U, "VK_KEY_U" }, - { VK_KEY_V, "VK_KEY_V" }, - { VK_KEY_W, "VK_KEY_W" }, - { VK_KEY_X, "VK_KEY_X" }, - { VK_KEY_Y, "VK_KEY_Y" }, - { VK_KEY_Z, "VK_KEY_Z" }, - { VK_LWIN, "VK_LWIN" }, - { VK_RWIN, "VK_RWIN" }, - { VK_APPS, "VK_APPS" }, - { 0, "" }, - { VK_SLEEP, "VK_SLEEP" }, - { VK_NUMPAD0, "VK_NUMPAD0" }, - { VK_NUMPAD1, "VK_NUMPAD1" }, - { VK_NUMPAD2, "VK_NUMPAD2" }, - { VK_NUMPAD3, "VK_NUMPAD3" }, - { VK_NUMPAD4, "VK_NUMPAD4" }, - { VK_NUMPAD5, "VK_NUMPAD5" }, - { VK_NUMPAD6, "VK_NUMPAD6" }, - { VK_NUMPAD7, "VK_NUMPAD7" }, - { VK_NUMPAD8, "VK_NUMPAD8" }, - { VK_NUMPAD9, "VK_NUMPAD9" }, - { VK_MULTIPLY, "VK_MULTIPLY" }, - { VK_ADD, "VK_ADD" }, - { VK_SEPARATOR, "VK_SEPARATOR" }, - { VK_SUBTRACT, "VK_SUBTRACT" }, - { VK_DECIMAL, "VK_DECIMAL" }, - { VK_DIVIDE, "VK_DIVIDE" }, - { VK_F1, "VK_F1" }, - { VK_F2, "VK_F2" }, - { VK_F3, "VK_F3" }, - { VK_F4, "VK_F4" }, - { VK_F5, "VK_F5" }, - { VK_F6, "VK_F6" }, - { VK_F7, "VK_F7" }, - { VK_F8, "VK_F8" }, - { VK_F9, "VK_F9" }, - { VK_F10, "VK_F10" }, - { VK_F11, "VK_F11" }, - { VK_F12, "VK_F12" }, - { VK_F13, "VK_F13" }, - { VK_F14, "VK_F14" }, - { VK_F15, "VK_F15" }, - { VK_F16, "VK_F16" }, - { VK_F17, "VK_F17" }, - { VK_F18, "VK_F18" }, - { VK_F19, "VK_F19" }, - { VK_F20, "VK_F20" }, - { VK_F21, "VK_F21" }, - { VK_F22, "VK_F22" }, - { VK_F23, "VK_F23" }, - { VK_F24, "VK_F24" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { VK_NUMLOCK, "VK_NUMLOCK" }, - { VK_SCROLL, "VK_SCROLL" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { VK_LSHIFT, "VK_LSHIFT" }, - { VK_RSHIFT, "VK_RSHIFT" }, - { VK_LCONTROL, "VK_LCONTROL" }, - { VK_RCONTROL, "VK_RCONTROL" }, - { VK_LMENU, "VK_LMENU" }, - { VK_RMENU, "VK_RMENU" }, - { VK_BROWSER_BACK, "VK_BROWSER_BACK" }, - { VK_BROWSER_FORWARD, "VK_BROWSER_FORWARD" }, - { VK_BROWSER_REFRESH, "VK_BROWSER_REFRESH" }, - { VK_BROWSER_STOP, "VK_BROWSER_STOP" }, - { VK_BROWSER_SEARCH, "VK_BROWSER_SEARCH" }, - { VK_BROWSER_FAVORITES, "VK_BROWSER_FAVORITES" }, - { VK_BROWSER_HOME, "VK_BROWSER_HOME" }, - { VK_VOLUME_MUTE, "VK_VOLUME_MUTE" }, - { VK_VOLUME_DOWN, "VK_VOLUME_DOWN" }, - { VK_VOLUME_UP, "VK_VOLUME_UP" }, - { VK_MEDIA_NEXT_TRACK, "VK_MEDIA_NEXT_TRACK" }, - { VK_MEDIA_PREV_TRACK, "VK_MEDIA_PREV_TRACK" }, - { VK_MEDIA_STOP, "VK_MEDIA_STOP" }, - { VK_MEDIA_PLAY_PAUSE, "VK_MEDIA_PLAY_PAUSE" }, - { VK_LAUNCH_MAIL, "VK_LAUNCH_MAIL" }, - { VK_MEDIA_SELECT, "VK_MEDIA_SELECT" }, - { VK_LAUNCH_APP1, "VK_LAUNCH_APP1" }, - { VK_LAUNCH_APP2, "VK_LAUNCH_APP2" }, - { 0, "" }, - { 0, "" }, - { VK_OEM_1, "VK_OEM_1" }, - { VK_OEM_PLUS, "VK_OEM_PLUS" }, - { VK_OEM_COMMA, "VK_OEM_COMMA" }, - { VK_OEM_MINUS, "VK_OEM_MINUS" }, - { VK_OEM_PERIOD, "VK_OEM_PERIOD" }, - { VK_OEM_2, "VK_OEM_2" }, - { VK_OEM_3, "VK_OEM_3" }, - { VK_ABNT_C1, "VK_ABNT_C1" }, - { VK_ABNT_C2, "VK_ABNT_C2" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { VK_OEM_4, "VK_OEM_4" }, - { VK_OEM_5, "VK_OEM_5" }, - { VK_OEM_6, "VK_OEM_6" }, - { VK_OEM_7, "VK_OEM_7" }, - { VK_OEM_8, "VK_OEM_8" }, - { 0, "" }, - { 0, "" }, - { VK_OEM_102, "VK_OEM_102" }, - { 0, "" }, - { 0, "" }, - { VK_PROCESSKEY, "VK_PROCESSKEY" }, - { 0, "" }, - { VK_PACKET, "VK_PACKET" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { 0, "" }, - { VK_ATTN, "VK_ATTN" }, - { VK_CRSEL, "VK_CRSEL" }, - { VK_EXSEL, "VK_EXSEL" }, - { VK_EREOF, "VK_EREOF" }, - { VK_PLAY, "VK_PLAY" }, - { VK_ZOOM, "VK_ZOOM" }, - { VK_NONAME, "VK_NONAME" }, - { VK_PA1, "VK_PA1" }, - { VK_OEM_CLEAR, "VK_OEM_CLEAR" }, - { 0, "" } -}; - -const char* freerdp_keyboard_get_virtual_key_code_name(UINT32 vkcode) -{ - return VIRTUAL_KEY_CODE_TABLE[vkcode].name; -} - -UINT32 freerdp_keyboard_get_virtual_key_code_from_name(const char* vkcode_name) -{ - int i = 0; - for (i = 0; i < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE); i++) - { - if (VIRTUAL_KEY_CODE_TABLE[i].name) - { - if (strcmp(vkcode_name, VIRTUAL_KEY_CODE_TABLE[i].name) == 0) - { - return VIRTUAL_KEY_CODE_TABLE[i].code; - } - } - } - return 0; -} diff --git a/winpr/include/winpr/input.h b/winpr/include/winpr/input.h index ecc43cd7a..eab316c45 100644 --- a/winpr/include/winpr/input.h +++ b/winpr/include/winpr/input.h @@ -23,6 +23,19 @@ #include #include +/** + * Key Flags + */ + +#define KBDEXT (USHORT) 0x0100 +#define KBDMULTIVK (USHORT) 0x0200 +#define KBDSPECIAL (USHORT) 0x0400 +#define KBDNUMPAD (USHORT) 0x0800 +#define KBDUNICODE (USHORT) 0x1000 +#define KBDINJECTEDVK (USHORT) 0x2000 +#define KBDMAPPEDVK (USHORT) 0x4000 +#define KBDBREAK (USHORT) 0x8000 + /* * Virtual Key Codes (Windows): * http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731/ @@ -688,4 +701,14 @@ #define KBD7_Y1D VK_PAUSE +/** + * Functions + */ + +WINPR_API char* GetVirtualKeyName(DWORD vkcode); +WINPR_API DWORD GetVirtualKeyCodeFromName(const char* vkname); + +WINPR_API DWORD GetVirtualKeyCodeFromVirtualScanCode(DWORD scancode, DWORD dwKeyboardType); +WINPR_API DWORD GetVirtualScanCodeFromVirtualKeyCode(DWORD vkcode, DWORD dwKeyboardType); + #endif /* WINPR_INPUT_H */ diff --git a/winpr/libwinpr/input/keyboard.c b/winpr/libwinpr/input/keyboard.c index 6236c3d1a..8a53ec1ab 100644 --- a/winpr/libwinpr/input/keyboard.c +++ b/winpr/libwinpr/input/keyboard.c @@ -25,6 +25,313 @@ #include +/** + * Virtual Key Codes + */ + +struct _VIRTUAL_KEY_CODE +{ + DWORD code; /* Windows Virtual Key Code */ + const char* name; /* Virtual Key Code Name */ +}; +typedef struct _VIRTUAL_KEY_CODE VIRTUAL_KEY_CODE; + +static const VIRTUAL_KEY_CODE VIRTUAL_KEY_CODE_TABLE[256] = +{ + { 0, NULL }, + { VK_LBUTTON, "VK_LBUTTON" }, + { VK_RBUTTON, "VK_RBUTTON" }, + { VK_CANCEL, "VK_CANCEL" }, + { VK_MBUTTON, "VK_MBUTTON" }, + { VK_XBUTTON1, "VK_XBUTTON1" }, + { VK_XBUTTON2, "VK_XBUTTON2" }, + { 0, NULL }, + { VK_BACK, "VK_BACK" }, + { VK_TAB, "VK_TAB" }, + { 0, NULL }, + { 0, NULL }, + { VK_CLEAR, "VK_CLEAR" }, + { VK_RETURN, "VK_RETURN" }, + { 0, NULL }, + { 0, NULL }, + { VK_SHIFT, "VK_SHIFT" }, + { VK_CONTROL, "VK_CONTROL" }, + { VK_MENU, "VK_MENU" }, + { VK_PAUSE, "VK_PAUSE" }, + { VK_CAPITAL, "VK_CAPITAL" }, + { VK_KANA, "VK_KANA" }, /* also VK_HANGUL */ + { 0, NULL }, + { VK_JUNJA, "VK_JUNJA" }, + { VK_FINAL, "VK_FINAL" }, + { VK_KANJI, "VK_KANJI" }, /* also VK_HANJA */ + { 0, NULL }, + { VK_ESCAPE, "VK_ESCAPE" }, + { VK_CONVERT, "VK_CONVERT" }, + { VK_NONCONVERT, "VK_NONCONVERT" }, + { VK_ACCEPT, "VK_ACCEPT" }, + { VK_MODECHANGE, "VK_MODECHANGE" }, + { VK_SPACE, "VK_SPACE" }, + { VK_PRIOR, "VK_PRIOR" }, + { VK_NEXT, "VK_NEXT" }, + { VK_END, "VK_END" }, + { VK_HOME, "VK_HOME" }, + { VK_LEFT, "VK_LEFT" }, + { VK_UP, "VK_UP" }, + { VK_RIGHT, "VK_RIGHT" }, + { VK_DOWN, "VK_DOWN" }, + { VK_SELECT, "VK_SELECT" }, + { VK_PRINT, "VK_PRINT" }, + { VK_EXECUTE, "VK_EXECUTE" }, + { VK_SNAPSHOT, "VK_SNAPSHOT" }, + { VK_INSERT, "VK_INSERT" }, + { VK_DELETE, "VK_DELETE" }, + { VK_HELP, "VK_HELP" }, + { VK_KEY_0, "VK_KEY_0" }, + { VK_KEY_1, "VK_KEY_1" }, + { VK_KEY_2, "VK_KEY_2" }, + { VK_KEY_3, "VK_KEY_3" }, + { VK_KEY_4, "VK_KEY_4" }, + { VK_KEY_5, "VK_KEY_5" }, + { VK_KEY_6, "VK_KEY_6" }, + { VK_KEY_7, "VK_KEY_7" }, + { VK_KEY_8, "VK_KEY_8" }, + { VK_KEY_9, "VK_KEY_9" }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { VK_KEY_A, "VK_KEY_A" }, + { VK_KEY_B, "VK_KEY_B" }, + { VK_KEY_C, "VK_KEY_C" }, + { VK_KEY_D, "VK_KEY_D" }, + { VK_KEY_E, "VK_KEY_E" }, + { VK_KEY_F, "VK_KEY_F" }, + { VK_KEY_G, "VK_KEY_G" }, + { VK_KEY_H, "VK_KEY_H" }, + { VK_KEY_I, "VK_KEY_I" }, + { VK_KEY_J, "VK_KEY_J" }, + { VK_KEY_K, "VK_KEY_K" }, + { VK_KEY_L, "VK_KEY_L" }, + { VK_KEY_M, "VK_KEY_M" }, + { VK_KEY_N, "VK_KEY_N" }, + { VK_KEY_O, "VK_KEY_O" }, + { VK_KEY_P, "VK_KEY_P" }, + { VK_KEY_Q, "VK_KEY_Q" }, + { VK_KEY_R, "VK_KEY_R" }, + { VK_KEY_S, "VK_KEY_S" }, + { VK_KEY_T, "VK_KEY_T" }, + { VK_KEY_U, "VK_KEY_U" }, + { VK_KEY_V, "VK_KEY_V" }, + { VK_KEY_W, "VK_KEY_W" }, + { VK_KEY_X, "VK_KEY_X" }, + { VK_KEY_Y, "VK_KEY_Y" }, + { VK_KEY_Z, "VK_KEY_Z" }, + { VK_LWIN, "VK_LWIN" }, + { VK_RWIN, "VK_RWIN" }, + { VK_APPS, "VK_APPS" }, + { 0, NULL }, + { VK_SLEEP, "VK_SLEEP" }, + { VK_NUMPAD0, "VK_NUMPAD0" }, + { VK_NUMPAD1, "VK_NUMPAD1" }, + { VK_NUMPAD2, "VK_NUMPAD2" }, + { VK_NUMPAD3, "VK_NUMPAD3" }, + { VK_NUMPAD4, "VK_NUMPAD4" }, + { VK_NUMPAD5, "VK_NUMPAD5" }, + { VK_NUMPAD6, "VK_NUMPAD6" }, + { VK_NUMPAD7, "VK_NUMPAD7" }, + { VK_NUMPAD8, "VK_NUMPAD8" }, + { VK_NUMPAD9, "VK_NUMPAD9" }, + { VK_MULTIPLY, "VK_MULTIPLY" }, + { VK_ADD, "VK_ADD" }, + { VK_SEPARATOR, "VK_SEPARATOR" }, + { VK_SUBTRACT, "VK_SUBTRACT" }, + { VK_DECIMAL, "VK_DECIMAL" }, + { VK_DIVIDE, "VK_DIVIDE" }, + { VK_F1, "VK_F1" }, + { VK_F2, "VK_F2" }, + { VK_F3, "VK_F3" }, + { VK_F4, "VK_F4" }, + { VK_F5, "VK_F5" }, + { VK_F6, "VK_F6" }, + { VK_F7, "VK_F7" }, + { VK_F8, "VK_F8" }, + { VK_F9, "VK_F9" }, + { VK_F10, "VK_F10" }, + { VK_F11, "VK_F11" }, + { VK_F12, "VK_F12" }, + { VK_F13, "VK_F13" }, + { VK_F14, "VK_F14" }, + { VK_F15, "VK_F15" }, + { VK_F16, "VK_F16" }, + { VK_F17, "VK_F17" }, + { VK_F18, "VK_F18" }, + { VK_F19, "VK_F19" }, + { VK_F20, "VK_F20" }, + { VK_F21, "VK_F21" }, + { VK_F22, "VK_F22" }, + { VK_F23, "VK_F23" }, + { VK_F24, "VK_F24" }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { VK_NUMLOCK, "VK_NUMLOCK" }, + { VK_SCROLL, "VK_SCROLL" }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { VK_LSHIFT, "VK_LSHIFT" }, + { VK_RSHIFT, "VK_RSHIFT" }, + { VK_LCONTROL, "VK_LCONTROL" }, + { VK_RCONTROL, "VK_RCONTROL" }, + { VK_LMENU, "VK_LMENU" }, + { VK_RMENU, "VK_RMENU" }, + { VK_BROWSER_BACK, "VK_BROWSER_BACK" }, + { VK_BROWSER_FORWARD, "VK_BROWSER_FORWARD" }, + { VK_BROWSER_REFRESH, "VK_BROWSER_REFRESH" }, + { VK_BROWSER_STOP, "VK_BROWSER_STOP" }, + { VK_BROWSER_SEARCH, "VK_BROWSER_SEARCH" }, + { VK_BROWSER_FAVORITES, "VK_BROWSER_FAVORITES" }, + { VK_BROWSER_HOME, "VK_BROWSER_HOME" }, + { VK_VOLUME_MUTE, "VK_VOLUME_MUTE" }, + { VK_VOLUME_DOWN, "VK_VOLUME_DOWN" }, + { VK_VOLUME_UP, "VK_VOLUME_UP" }, + { VK_MEDIA_NEXT_TRACK, "VK_MEDIA_NEXT_TRACK" }, + { VK_MEDIA_PREV_TRACK, "VK_MEDIA_PREV_TRACK" }, + { VK_MEDIA_STOP, "VK_MEDIA_STOP" }, + { VK_MEDIA_PLAY_PAUSE, "VK_MEDIA_PLAY_PAUSE" }, + { VK_LAUNCH_MAIL, "VK_LAUNCH_MAIL" }, + { VK_MEDIA_SELECT, "VK_MEDIA_SELECT" }, + { VK_LAUNCH_APP1, "VK_LAUNCH_APP1" }, + { VK_LAUNCH_APP2, "VK_LAUNCH_APP2" }, + { 0, NULL }, + { 0, NULL }, + { VK_OEM_1, "VK_OEM_1" }, + { VK_OEM_PLUS, "VK_OEM_PLUS" }, + { VK_OEM_COMMA, "VK_OEM_COMMA" }, + { VK_OEM_MINUS, "VK_OEM_MINUS" }, + { VK_OEM_PERIOD, "VK_OEM_PERIOD" }, + { VK_OEM_2, "VK_OEM_2" }, + { VK_OEM_3, "VK_OEM_3" }, + { VK_ABNT_C1, "VK_ABNT_C1" }, + { VK_ABNT_C2, "VK_ABNT_C2" }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { VK_OEM_4, "VK_OEM_4" }, + { VK_OEM_5, "VK_OEM_5" }, + { VK_OEM_6, "VK_OEM_6" }, + { VK_OEM_7, "VK_OEM_7" }, + { VK_OEM_8, "VK_OEM_8" }, + { 0, NULL }, + { 0, NULL }, + { VK_OEM_102, "VK_OEM_102" }, + { 0, NULL }, + { 0, NULL }, + { VK_PROCESSKEY, "VK_PROCESSKEY" }, + { 0, NULL }, + { VK_PACKET, "VK_PACKET" }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + { VK_ATTN, "VK_ATTN" }, + { VK_CRSEL, "VK_CRSEL" }, + { VK_EXSEL, "VK_EXSEL" }, + { VK_EREOF, "VK_EREOF" }, + { VK_PLAY, "VK_PLAY" }, + { VK_ZOOM, "VK_ZOOM" }, + { VK_NONAME, "VK_NONAME" }, + { VK_PA1, "VK_PA1" }, + { VK_OEM_CLEAR, "VK_OEM_CLEAR" }, + { 0, NULL } +}; + +char* GetVirtualKeyName(DWORD vkcode) +{ + char* vkname; + + vkname = (char*) VIRTUAL_KEY_CODE_TABLE[vkcode].name; + + if (!vkname) + vkname = "VK_NONE"; + + return vkname; +} + +DWORD GetVirtualKeyCodeFromName(const char* vkname) +{ + int i; + + for (i = 0; i < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE); i++) + { + if (VIRTUAL_KEY_CODE_TABLE[i].name) + { + if (strcmp(vkname, VIRTUAL_KEY_CODE_TABLE[i].name) == 0) + return VIRTUAL_KEY_CODE_TABLE[i].code; + } + } + + return VK_NONE; +} + +/** + * Virtual Scan Codes + */ + +/** + * Keyboard Type 4 + */ + DWORD KBD4T[128] = { KBD4_T00, @@ -289,6 +596,10 @@ DWORD KBD4X[128] = VK_NONE }; +/** + * Keyboard Type 7 + */ + DWORD KBD7T[128] = { KBD7_T00, @@ -552,3 +863,90 @@ DWORD KBD7X[128] = VK_NONE, VK_NONE }; + +DWORD GetVirtualKeyCodeFromVirtualScanCode(DWORD scancode, DWORD dwKeyboardType) +{ + DWORD vkcode; + + vkcode = VK_NONE; + + if ((dwKeyboardType != 4) && (dwKeyboardType != 7)) + dwKeyboardType = 4; + + if (dwKeyboardType == 4) + { + if (scancode & KBDEXT) + vkcode = KBD4X[scancode & 0x7F]; + else + vkcode = KBD4T[scancode & 0x7F]; + } + else if (dwKeyboardType == 7) + { + if (scancode & KBDEXT) + vkcode = KBD7X[scancode & 0x7F]; + else + vkcode = KBD7T[scancode & 0x7F]; + } + + return vkcode; +} + +DWORD GetVirtualScanCodeFromVirtualKeyCode(DWORD vkcode, DWORD dwKeyboardType) +{ + int i; + DWORD scancode; + + scancode = 0; + + if ((dwKeyboardType != 4) && (dwKeyboardType != 7)) + dwKeyboardType = 4; + + if (dwKeyboardType == 4) + { + for (i = 0; i < 128; i++) + { + if (KBD4T[i] == vkcode) + { + scancode = i; + break; + } + } + + if (!scancode) + { + for (i = 0; i < 128; i++) + { + if (KBD4X[i] == vkcode) + { + scancode = i; + break; + } + } + } + } + else if (dwKeyboardType == 7) + { + for (i = 0; i < 128; i++) + { + if (KBD7T[i] == vkcode) + { + scancode = i; + break; + } + } + + if (!scancode) + { + for (i = 0; i < 128; i++) + { + if (KBD7X[i] == vkcode) + { + scancode = i; + break; + } + } + } + } + + return scancode; +}