diff --git a/SourceS/miniwin/misc.h b/SourceS/miniwin/misc.h index 7cf7691b1..4b6d55eee 100644 --- a/SourceS/miniwin/misc.h +++ b/SourceS/miniwin/misc.h @@ -723,48 +723,80 @@ constexpr auto DVL_WM_PALETTECHANGED = 0x0311; constexpr auto DVL_SC_CLOSE = 0xF060; -constexpr auto DVL_VK_RETURN = 0x0D; -constexpr auto DVL_VK_BACK = 0x08; -constexpr auto DVL_VK_SHIFT = 0x10; -constexpr auto DVL_VK_ESCAPE = 0x1B; -constexpr auto DVL_VK_SPACE = 0x20; -constexpr auto DVL_VK_LEFT = 0x25; -constexpr auto DVL_VK_UP = 0x26; -constexpr auto DVL_VK_RIGHT = 0x27; -constexpr auto DVL_VK_DOWN = 0x28; - -constexpr auto DVL_VK_F1 = 0x70; -constexpr auto DVL_VK_F2 = 0x71; -constexpr auto DVL_VK_F3 = 0x72; -constexpr auto DVL_VK_F4 = 0x73; -constexpr auto DVL_VK_F5 = 0x74; -constexpr auto DVL_VK_F6 = 0x75; -constexpr auto DVL_VK_F7 = 0x76; -constexpr auto DVL_VK_F8 = 0x77; -constexpr auto DVL_VK_F9 = 0x78; -constexpr auto DVL_VK_F10 = 0x79; -constexpr auto DVL_VK_F11 = 0x7A; -constexpr auto DVL_VK_F12 = 0x7B; - -constexpr auto DVL_VK_TAB = 0x09; -constexpr auto DVL_VK_PAUSE = 0x13; -constexpr auto DVL_VK_PRIOR = 0x21; -constexpr auto DVL_VK_NEXT = 0x22; -constexpr auto DVL_VK_SNAPSHOT = 0x2C; - -constexpr auto DVL_VK_OEM_1 = 0xBA; -constexpr auto DVL_VK_OEM_PLUS = 0xBB; -constexpr auto DVL_VK_OEM_COMMA = 0xBC; -constexpr auto DVL_VK_OEM_MINUS = 0xBD; -constexpr auto DVL_VK_OEM_PERIOD = 0xBE; -constexpr auto DVL_VK_OEM_2 = 0xBF; -constexpr auto DVL_VK_OEM_3 = 0xC0; -constexpr auto DVL_VK_OEM_4 = 0xDB; -constexpr auto DVL_VK_OEM_5 = 0xDC; -constexpr auto DVL_VK_OEM_6 = 0xDD; -constexpr auto DVL_VK_OEM_7 = 0xDE; -//constexpr auto DVL_VK_OEM_8 = 0xDF; -//constexpr auto DVL_VK_OEM_102 = 0xE2; +// Virtual key codes. +// +// ref: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes +constexpr auto DVL_VK_BACK = 0x08; // BACKSPACE key +constexpr auto DVL_VK_TAB = 0x09; // TAB key +constexpr auto DVL_VK_RETURN = 0x0D; // ENTER key +constexpr auto DVL_VK_SHIFT = 0x10; // SHIFT key +constexpr auto DVL_VK_CONTROL = 0x11; // CONTROL key +constexpr auto DVL_VK_MENU = 0x12; // ALT key +constexpr auto DVL_VK_PAUSE = 0x13; // PAUSE key +constexpr auto DVL_VK_CAPITAL = 0x14; // CAPS LOCK key +constexpr auto DVL_VK_ESCAPE = 0x1B; // ESC key +constexpr auto DVL_VK_SPACE = 0x20; // SPACEBAR +constexpr auto DVL_VK_PRIOR = 0x21; // PAGE UP key +constexpr auto DVL_VK_NEXT = 0x22; // PAGE DOWN key +constexpr auto DVL_VK_END = 0x23; // END key +constexpr auto DVL_VK_HOME = 0x24; // HOME key +constexpr auto DVL_VK_LEFT = 0x25; // LEFT ARROW key +constexpr auto DVL_VK_UP = 0x26; // UP ARROW key +constexpr auto DVL_VK_RIGHT = 0x27; // RIGHT ARROW key +constexpr auto DVL_VK_DOWN = 0x28; // DOWN ARROW key +constexpr auto DVL_VK_SNAPSHOT = 0x2C; // PRINT SCREEN key +constexpr auto DVL_VK_INSERT = 0x2D; // INS key +constexpr auto DVL_VK_DELETE = 0x2E; // DEL key +// DVL_VK_0 through DVL_VK_9 correspond to '0' - '9' +// DVL_VK_A through DVL_VK_Z correspond to 'A' - 'Z' +constexpr auto DVL_VK_LWIN = 0x5B; // Left Windows key (Natural keyboard) +constexpr auto DVL_VK_RWIN = 0x5C; // Right Windows key (Natural keyboard) +constexpr auto DVL_VK_NUMPAD0 = 0x60; // Numeric keypad 0 key +constexpr auto DVL_VK_NUMPAD1 = 0x61; // Numeric keypad 1 key +constexpr auto DVL_VK_NUMPAD2 = 0x62; // Numeric keypad 2 key +constexpr auto DVL_VK_NUMPAD3 = 0x63; // Numeric keypad 3 key +constexpr auto DVL_VK_NUMPAD4 = 0x64; // Numeric keypad 4 key +constexpr auto DVL_VK_NUMPAD5 = 0x65; // Numeric keypad 5 key +constexpr auto DVL_VK_NUMPAD6 = 0x66; // Numeric keypad 6 key +constexpr auto DVL_VK_NUMPAD7 = 0x67; // Numeric keypad 7 key +constexpr auto DVL_VK_NUMPAD8 = 0x68; // Numeric keypad 8 key +constexpr auto DVL_VK_NUMPAD9 = 0x69; // Numeric keypad 9 key +constexpr auto DVL_VK_MULTIPLY = 0x6A; // Multiply key +constexpr auto DVL_VK_ADD = 0x6B; // Add key +constexpr auto DVL_VK_SUBTRACT = 0x6D; // Subtract key +constexpr auto DVL_VK_DECIMAL = 0x6E; // Decimal key +constexpr auto DVL_VK_DIVIDE = 0x6F; // Divide key +constexpr auto DVL_VK_F1 = 0x70; // F1 key +constexpr auto DVL_VK_F2 = 0x71; // F2 key +constexpr auto DVL_VK_F3 = 0x72; // F3 key +constexpr auto DVL_VK_F4 = 0x73; // F4 key +constexpr auto DVL_VK_F5 = 0x74; // F5 key +constexpr auto DVL_VK_F6 = 0x75; // F6 key +constexpr auto DVL_VK_F7 = 0x76; // F7 key +constexpr auto DVL_VK_F8 = 0x77; // F8 key +constexpr auto DVL_VK_F9 = 0x78; // F9 key +constexpr auto DVL_VK_F10 = 0x79; // F10 key +constexpr auto DVL_VK_F11 = 0x7A; // F11 key +constexpr auto DVL_VK_F12 = 0x7B; // F12 key +constexpr auto DVL_VK_NUMLOCK = 0x90; // NUM LOCK key +constexpr auto DVL_VK_SCROLL = 0x91; // SCROLL LOCK key +constexpr auto DVL_VK_LSHIFT = 0xA0; // Left SHIFT key +constexpr auto DVL_VK_RSHIFT = 0xA1; // Right SHIFT key +constexpr auto DVL_VK_LCONTROL = 0xA2; // Left CONTROL key +constexpr auto DVL_VK_RCONTROL = 0xA3; // Right CONTROL key +constexpr auto DVL_VK_LMENU = 0xA4; // Left MENU key +constexpr auto DVL_VK_RMENU = 0xA5; // Right MENU key +constexpr auto DVL_VK_OEM_1 = 0xBA; // For the US standard keyboard, the ';:' key +constexpr auto DVL_VK_OEM_PLUS = 0xBB; // For any country/region, the '+' key +constexpr auto DVL_VK_OEM_COMMA = 0xBC; // For any country/region, the ',' key +constexpr auto DVL_VK_OEM_MINUS = 0xBD; // For any country/region, the '-' key +constexpr auto DVL_VK_OEM_PERIOD = 0xBE; // For any country/region, the '.' key +constexpr auto DVL_VK_OEM_2 = 0xBF; // For the US standard keyboard, the '/?' key +constexpr auto DVL_VK_OEM_3 = 0xC0; // For the US standard keyboard, the '`~' key +constexpr auto DVL_VK_OEM_4 = 0xDB; // For the US standard keyboard, the '[{' key +constexpr auto DVL_VK_OEM_5 = 0xDC; // For the US standard keyboard, the '\|' key +constexpr auto DVL_VK_OEM_6 = 0xDD; // For the US standard keyboard, the ']}' key +constexpr auto DVL_VK_OEM_7 = 0xDE; // For the US standard keyboard, the 'single-quote/double-quote' key constexpr auto DVL_MK_SHIFT = 0x0004; constexpr auto DVL_MK_LBUTTON = 0x0001; diff --git a/SourceS/miniwin/misc_macro.h b/SourceS/miniwin/misc_macro.h index 2bfe82a89..6aff296b2 100644 --- a/SourceS/miniwin/misc_macro.h +++ b/SourceS/miniwin/misc_macro.h @@ -282,48 +282,80 @@ #define SC_CLOSE DVL_SC_CLOSE -#define VK_RETURN DVL_VK_RETURN -#define VK_BACK DVL_VK_BACK -#define VK_SHIFT DVL_VK_SHIFT -#define VK_ESCAPE DVL_VK_ESCAPE -#define VK_SPACE DVL_VK_SPACE -#define VK_LEFT DVL_VK_LEFT -#define VK_UP DVL_VK_UP -#define VK_RIGHT DVL_VK_RIGHT -#define VK_DOWN DVL_VK_DOWN - -#define VK_F1 DVL_VK_F1 -#define VK_F2 DVL_VK_F2 -#define VK_F3 DVL_VK_F3 -#define VK_F4 DVL_VK_F4 -#define VK_F5 DVL_VK_F5 -#define VK_F6 DVL_VK_F6 -#define VK_F7 DVL_VK_F7 -#define VK_F8 DVL_VK_F8 -#define VK_F9 DVL_VK_F9 -#define VK_F10 DVL_VK_F10 -#define VK_F11 DVL_VK_F11 -#define VK_F12 DVL_VK_F12 - -#define VK_TAB DVL_VK_TAB -#define VK_PAUSE DVL_VK_PAUSE -#define VK_PRIOR DVL_VK_PRIOR -#define VK_NEXT DVL_VK_NEXT -#define VK_SNAPSHOT DVL_VK_SNAPSHOT - -#define VK_OEM_1 DVL_VK_OEM_1 -#define VK_OEM_PLUS DVL_VK_OEM_PLUS -#define VK_OEM_COMMA DVL_VK_OEM_COMMA -#define VK_OEM_MINUS DVL_VK_OEM_MINUS -#define VK_OEM_PERIOD DVL_VK_OEM_PERIOD -#define VK_OEM_2 DVL_VK_OEM_2 -#define VK_OEM_3 DVL_VK_OEM_3 -#define VK_OEM_4 DVL_VK_OEM_4 -#define VK_OEM_5 DVL_VK_OEM_5 -#define VK_OEM_6 DVL_VK_OEM_6 -#define VK_OEM_7 DVL_VK_OEM_7 -//#define VK_OEM_8 DVL_VK_OEM_8 -//#define VK_OEM_102 DVL_VK_OEM_102 +// Virtual key codes. +// +// ref: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes +#define VK_BACK DVL_VK_BACK // BACKSPACE key +#define VK_TAB DVL_VK_TAB // TAB key +#define VK_RETURN DVL_VK_RETURN // ENTER key +#define VK_SHIFT DVL_VK_SHIFT // SHIFT key +#define VK_CONTROL DVL_VK_CONTROL // CONTROL key +#define VK_MENU DVL_VK_MENU // ALT key +#define VK_PAUSE DVL_VK_PAUSE // PAUSE key +#define VK_CAPITAL DVL_VK_CAPITAL // CAPS LOCK key +#define VK_ESCAPE DVL_VK_ESCAPE // ESC key +#define VK_SPACE DVL_VK_SPACE // SPACEBAR +#define VK_PRIOR DVL_VK_PRIOR // PAGE UP key +#define VK_NEXT DVL_VK_NEXT // PAGE DOWN key +#define VK_END DVL_VK_END // END key +#define VK_HOME DVL_VK_HOME // HOME key +#define VK_LEFT DVL_VK_LEFT // LEFT ARROW key +#define VK_UP DVL_VK_UP // UP ARROW key +#define VK_RIGHT DVL_VK_RIGHT // RIGHT ARROW key +#define VK_DOWN DVL_VK_DOWN // DOWN ARROW key +#define VK_SNAPSHOT DVL_VK_SNAPSHOT // PRINT SCREEN key +#define VK_INSERT DVL_VK_INSERT // INS key +#define VK_DELETE DVL_VK_DELETE // DEL key +// VK_0 through VK_9 correspond to '0' - '9' +// VK_A through VK_Z correspond to 'A' - 'Z' +#define VK_LWIN DVL_VK_LWIN // Left Windows key (Natural keyboard) +#define VK_RWIN DVL_VK_RWIN // Right Windows key (Natural keyboard) +#define VK_NUMPAD0 DVL_VK_NUMPAD0 // Numeric keypad 0 key +#define VK_NUMPAD1 DVL_VK_NUMPAD1 // Numeric keypad 1 key +#define VK_NUMPAD2 DVL_VK_NUMPAD2 // Numeric keypad 2 key +#define VK_NUMPAD3 DVL_VK_NUMPAD3 // Numeric keypad 3 key +#define VK_NUMPAD4 DVL_VK_NUMPAD4 // Numeric keypad 4 key +#define VK_NUMPAD5 DVL_VK_NUMPAD5 // Numeric keypad 5 key +#define VK_NUMPAD6 DVL_VK_NUMPAD6 // Numeric keypad 6 key +#define VK_NUMPAD7 DVL_VK_NUMPAD7 // Numeric keypad 7 key +#define VK_NUMPAD8 DVL_VK_NUMPAD8 // Numeric keypad 8 key +#define VK_NUMPAD9 DVL_VK_NUMPAD9 // Numeric keypad 9 key +#define VK_MULTIPLY DVL_VK_MULTIPLY // Multiply key +#define VK_ADD DVL_VK_ADD // Add key +#define VK_SUBTRACT DVL_VK_SUBTRACT // Subtract key +#define VK_DECIMAL DVL_VK_DECIMAL // Decimal key +#define VK_DIVIDE DVL_VK_DIVIDE // Divide key +#define VK_F1 DVL_VK_F1 // F1 key +#define VK_F2 DVL_VK_F2 // F2 key +#define VK_F3 DVL_VK_F3 // F3 key +#define VK_F4 DVL_VK_F4 // F4 key +#define VK_F5 DVL_VK_F5 // F5 key +#define VK_F6 DVL_VK_F6 // F6 key +#define VK_F7 DVL_VK_F7 // F7 key +#define VK_F8 DVL_VK_F8 // F8 key +#define VK_F9 DVL_VK_F9 // F9 key +#define VK_F10 DVL_VK_F10 // F10 key +#define VK_F11 DVL_VK_F11 // F11 key +#define VK_F12 DVL_VK_F12 // F12 key +#define VK_NUMLOCK DVL_VK_NUMLOCK // NUM LOCK key +#define VK_SCROLL DVL_VK_SCROLL // SCROLL LOCK key +#define VK_LSHIFT DVL_VK_LSHIFT // Left SHIFT key +#define VK_RSHIFT DVL_VK_RSHIFT // Right SHIFT key +#define VK_LCONTROL DVL_VK_LCONTROL // Left CONTROL key +#define VK_RCONTROL DVL_VK_RCONTROL // Right CONTROL key +#define VK_LMENU DVL_VK_LMENU // Left MENU key +#define VK_RMENU DVL_VK_RMENU // Right MENU key +#define VK_OEM_1 DVL_VK_OEM_1 // For the US standard keyboard, the ';:' key +#define VK_OEM_PLUS DVL_VK_OEM_PLUS // For any country/region, the '+' key +#define VK_OEM_COMMA DVL_VK_OEM_COMMA // For any country/region, the ',' key +#define VK_OEM_MINUS DVL_VK_OEM_MINUS // For any country/region, the '-' key +#define VK_OEM_PERIOD DVL_VK_OEM_PERIOD // For any country/region, the '.' key +#define VK_OEM_2 DVL_VK_OEM_2 // For the US standard keyboard, the '/?' key +#define VK_OEM_3 DVL_VK_OEM_3 // For the US standard keyboard, the '`~' key +#define VK_OEM_4 DVL_VK_OEM_4 // For the US standard keyboard, the '[{' key +#define VK_OEM_5 DVL_VK_OEM_5 // For the US standard keyboard, the '\|' key +#define VK_OEM_6 DVL_VK_OEM_6 // For the US standard keyboard, the ']}' key +#define VK_OEM_7 DVL_VK_OEM_7 // For the US standard keyboard, the 'single-quote/double-quote' key #define MK_SHIFT DVL_MK_SHIFT #define MK_LBUTTON DVL_MK_LBUTTON diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 28e009f94..31bf16d06 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -15,68 +15,154 @@ static std::deque message_queue; static int translate_sdl_key(SDL_Keysym key) { + // ref: https://wiki.libsdl.org/SDL_Keycode + // ref: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes int sym = key.sym; switch (sym) { - case SDLK_ESCAPE: - return DVL_VK_ESCAPE; - case SDLK_RETURN: - case SDLK_KP_ENTER: - return DVL_VK_RETURN; + case SDLK_BACKSPACE: + return DVL_VK_BACK; case SDLK_TAB: return DVL_VK_TAB; + case SDLK_RETURN: + return DVL_VK_RETURN; + case SDLK_ESCAPE: + return DVL_VK_ESCAPE; case SDLK_SPACE: return DVL_VK_SPACE; - case SDLK_BACKSPACE: - return DVL_VK_BACK; - - case SDLK_DOWN: - return DVL_VK_DOWN; - case SDLK_LEFT: - return DVL_VK_LEFT; - case SDLK_RIGHT: - return DVL_VK_RIGHT; - case SDLK_UP: - return DVL_VK_UP; - - case SDLK_PAGEUP: - return DVL_VK_PRIOR; - case SDLK_PAGEDOWN: - return DVL_VK_NEXT; - - case SDLK_PAUSE: - return DVL_VK_PAUSE; - + case SDLK_QUOTE: + return DVL_VK_OEM_7; + case SDLK_COMMA: + return DVL_VK_OEM_COMMA; + case SDLK_MINUS: + return DVL_VK_OEM_MINUS; + case SDLK_PERIOD: + return DVL_VK_OEM_PERIOD; + case SDLK_SLASH: + return DVL_VK_OEM_2; case SDLK_SEMICOLON: return DVL_VK_OEM_1; - case SDLK_QUESTION: - return DVL_VK_OEM_2; - case SDLK_BACKQUOTE: - return DVL_VK_OEM_3; + case SDLK_EQUALS: + return DVL_VK_OEM_PLUS; case SDLK_LEFTBRACKET: return DVL_VK_OEM_4; case SDLK_BACKSLASH: return DVL_VK_OEM_5; case SDLK_RIGHTBRACKET: return DVL_VK_OEM_6; - case SDLK_QUOTE: - return DVL_VK_OEM_7; - case SDLK_MINUS: + case SDLK_BACKQUOTE: + return DVL_VK_OEM_3; + case SDLK_DELETE: + return DVL_VK_DELETE; + case SDLK_CAPSLOCK: + return DVL_VK_CAPITAL; + case SDLK_F1: + return DVL_VK_F1; + case SDLK_F2: + return DVL_VK_F2; + case SDLK_F3: + return DVL_VK_F3; + case SDLK_F4: + return DVL_VK_F4; + case SDLK_F5: + return DVL_VK_F5; + case SDLK_F6: + return DVL_VK_F6; + case SDLK_F7: + return DVL_VK_F7; + case SDLK_F8: + return DVL_VK_F8; + case SDLK_F9: + return DVL_VK_F9; + case SDLK_F10: + return DVL_VK_F10; + case SDLK_F11: + return DVL_VK_F11; + case SDLK_F12: + return DVL_VK_F12; + case SDLK_PRINTSCREEN: + return DVL_VK_SNAPSHOT; + case SDLK_SCROLLLOCK: + return DVL_VK_SCROLL; + case SDLK_PAUSE: + return DVL_VK_PAUSE; + case SDLK_INSERT: + return DVL_VK_INSERT; + case SDLK_HOME: + return DVL_VK_HOME; + case SDLK_PAGEUP: + return DVL_VK_PRIOR; + case SDLK_END: + return DVL_VK_END; + case SDLK_PAGEDOWN: + return DVL_VK_NEXT; + case SDLK_RIGHT: + return DVL_VK_RIGHT; + case SDLK_LEFT: + return DVL_VK_LEFT; + case SDLK_DOWN: + return DVL_VK_DOWN; + case SDLK_UP: + return DVL_VK_UP; + case SDLK_NUMLOCKCLEAR: + return DVL_VK_NUMLOCK; + case SDLK_KP_DIVIDE: + return DVL_VK_DIVIDE; + case SDLK_KP_MULTIPLY: + return DVL_VK_MULTIPLY; case SDLK_KP_MINUS: + // Returning DVL_VK_OEM_MINUS to play nice with Devilution automap zoom. + // + // For a distinct keypad key-code, DVL_VK_SUBTRACT should be returned. return DVL_VK_OEM_MINUS; - case SDLK_PLUS: - case SDLK_EQUALS: case SDLK_KP_PLUS: + // Returning DVL_VK_OEM_PLUS to play nice with Devilution automap zoom. + // + // For a distinct keypad key-code, DVL_VK_ADD should be returned. return DVL_VK_OEM_PLUS; - case SDLK_PERIOD: - return DVL_VK_OEM_PERIOD; - case SDLK_COMMA: + case SDLK_KP_ENTER: + return DVL_VK_RETURN; + case SDLK_KP_1: + return DVL_VK_NUMPAD1; + case SDLK_KP_2: + return DVL_VK_NUMPAD2; + case SDLK_KP_3: + return DVL_VK_NUMPAD3; + case SDLK_KP_4: + return DVL_VK_NUMPAD4; + case SDLK_KP_5: + return DVL_VK_NUMPAD5; + case SDLK_KP_6: + return DVL_VK_NUMPAD6; + case SDLK_KP_7: + return DVL_VK_NUMPAD7; + case SDLK_KP_8: + return DVL_VK_NUMPAD8; + case SDLK_KP_9: + return DVL_VK_NUMPAD9; + case SDLK_KP_0: + return DVL_VK_NUMPAD0; + case SDLK_KP_PERIOD: + return DVL_VK_DECIMAL; + case SDLK_MENU: + return DVL_VK_MENU; + case SDLK_KP_COMMA: return DVL_VK_OEM_COMMA; + case SDLK_LCTRL: + return DVL_VK_LCONTROL; case SDLK_LSHIFT: + return DVL_VK_LSHIFT; + case SDLK_LALT: + return DVL_VK_LMENU; + case SDLK_LGUI: + return DVL_VK_LWIN; + case SDLK_RCTRL: + return DVL_VK_RCONTROL; case SDLK_RSHIFT: - return DVL_VK_SHIFT; - case SDLK_PRINTSCREEN: - return DVL_VK_SNAPSHOT; - + return DVL_VK_RSHIFT; + case SDLK_RALT: + return DVL_VK_RMENU; + case SDLK_RGUI: + return DVL_VK_RWIN; default: if (sym >= SDLK_a && sym <= SDLK_z) { return 'A' + (sym - SDLK_a);