From e27fcf64a80aded34d5c45635d913699034df109 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Sun, 19 May 2024 23:56:54 +0900 Subject: [PATCH] (Win32) Fix numlock/pause key release events On Win32, the numlock and pause keys need special handling. But the existing code did only handle it correctly for pressing and not releasing. It separately called GetKeyState for the two keys which only returned true while pressing a key and not while releasing it. This then caused the releasing of the pause key to be treated as releasing the numlock key and vice versa. This fix handles releasing the two keys correctly. --- gfx/common/win32_common.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 7c48730d2a..83d54348b6 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -1091,16 +1091,14 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, unsigned keysym = (lparam >> 16) & 0xff; bool extended = (lparam >> 24) & 0x1; + /* NumLock vs Pause correction */ + if (keysym == 0x45 && (wparam == VK_NUMLOCK || wparam == VK_PAUSE)) + extended = !extended; + /* extended keys will map to dinput if the high bit is set */ if (extended) keysym |= 0x80; - /* NumLock vs Pause correction */ - if (GetKeyState(VK_NUMLOCK) & 0x80 && extended) - keysym &= ~0x80; - else if (GetKeyState(VK_PAUSE) & 0x80 && !extended) - keysym |= 0x80; - keycode = input_keymaps_translate_keysym_to_rk(keysym); if (GetKeyState(VK_SHIFT) & 0x80) @@ -1344,16 +1342,14 @@ static LRESULT CALLBACK wnd_proc_common_dinput_internal(HWND hwnd, unsigned keysym = (lparam >> 16) & 0xff; bool extended = (lparam >> 24) & 0x1; + /* NumLock vs Pause correction */ + if (keysym == 0x45 && (wparam == VK_NUMLOCK || wparam == VK_PAUSE)) + extended = !extended; + /* extended keys will map to dinput if the high bit is set */ if (extended) keysym |= 0x80; - /* NumLock vs Pause correction */ - if (GetKeyState(VK_NUMLOCK) & 0x80 && extended) - keysym &= ~0x80; - else if (GetKeyState(VK_PAUSE) & 0x80 && !extended) - keysym |= 0x80; - keycode = input_keymaps_translate_keysym_to_rk(keysym); switch (keycode) {