From 3152b98e8702726170e052ede4d06364540386d0 Mon Sep 17 00:00:00 2001 From: Dimitriy Ryazantcev Date: Wed, 20 Dec 2023 13:54:29 +0200 Subject: [PATCH] win32: minor fixup in WIN_UpdateKeymap() Remove unused defines in SDL_windowsevents.c --- src/video/windows/SDL_windowsevents.c | 9 --------- src/video/windows/SDL_windowskeyboard.c | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index c4e9cf86cf..3a8c89337f 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -51,15 +51,6 @@ /* #define HIGHDPI_DEBUG */ -/* Masks for processing the windows KEYDOWN and KEYUP messages */ -#define REPEATED_KEYMASK (1 << 30) -#define EXTENDED_KEYMASK (1 << 24) - -#define VK_ENTER 10 /* Keypad Enter ... no VKEY defined? */ -#ifndef VK_OEM_NEC_EQUAL -#define VK_OEM_NEC_EQUAL 0x92 -#endif - /* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */ #ifndef WM_XBUTTONDOWN #define WM_XBUTTONDOWN 0x020B diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index f84c1bdc95..9c5db83ee1 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -120,7 +120,9 @@ void WIN_UpdateKeymap(SDL_bool send_event) WIN_ResetDeadKeys(); for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) { - int vk; + Uint8 vk; + Uint16 sc; + /* Make sure this scancode is a valid character scancode */ scancode = windows_scancode_table[i]; if (scancode == SDL_SCANCODE_UNKNOWN) { @@ -133,7 +135,9 @@ void WIN_UpdateKeymap(SDL_bool send_event) continue; } - vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); + /* Unpack the single byte index to make the scan code. */ + sc = MAKEWORD(i & 0x7f, (i & 0x80) ? 0xe0 : 0x00); + vk = LOBYTE(MapVirtualKey(sc, MAPVK_VSC_TO_VK)); if (!vk) { continue; } @@ -147,8 +151,8 @@ void WIN_UpdateKeymap(SDL_bool send_event) BYTE keyboardState[256] = { 0 }; WCHAR buffer[16] = { 0 }; Uint32 *ch = 0; - int result = ToUnicode(vk, i, keyboardState, buffer, 16, 0); - buffer[SDL_abs(result) + 1] = 0; + int result = ToUnicode(vk, sc, keyboardState, buffer, 16, 0); + buffer[SDL_abs(result)] = 0; /* Convert UTF-16 to UTF-32 code points */ ch = (Uint32 *)SDL_iconv_string("UTF-32LE", "UTF-16LE", (const char *)buffer, (SDL_abs(result) + 1) * sizeof(WCHAR)); @@ -196,21 +200,21 @@ void WIN_ResetDeadKeys() */ BYTE keyboardState[256]; WCHAR buffer[16]; - int keycode, scancode, result, i; + int vk, sc, result, i; if (!GetKeyboardState(keyboardState)) { return; } - keycode = VK_SPACE; - scancode = MapVirtualKey(keycode, MAPVK_VK_TO_VSC); - if (scancode == 0) { + vk = VK_SPACE; + sc = MapVirtualKey(vk, MAPVK_VK_TO_VSC); + if (sc == 0) { /* the keyboard doesn't have this key */ return; } for (i = 0; i < 5; i++) { - result = ToUnicode(keycode, scancode, keyboardState, buffer, 16, 0); + result = ToUnicode(vk, sc, keyboardState, buffer, 16, 0); if (result > 0) { /* success */ return;