From b8fe1d8271fe52e9c36f4fb469f4f881e7988096 Mon Sep 17 00:00:00 2001 From: sonninnos Date: Sat, 29 Jul 2023 17:24:42 +0300 Subject: [PATCH] (WIN32) Fix Pause vs NumLock in dinput/sdl2 --- gfx/common/win32_common.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 0e032a08d6b..e2148f23fcb 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -1081,9 +1081,16 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, uint16_t mod = 0; unsigned keycode = 0; unsigned keysym = (lparam >> 16) & 0xff; + bool extended = (lparam >> 24) & 0x1; /* extended keys will map to dinput if the high bit is set */ - if ((lparam >> 24 & 0x1)) + 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); @@ -1327,9 +1334,16 @@ static LRESULT CALLBACK wnd_proc_common_dinput_internal(HWND hwnd, uint16_t mod = 0; unsigned keycode = 0; unsigned keysym = (lparam >> 16) & 0xff; + bool extended = (lparam >> 24) & 0x1; /* extended keys will map to dinput if the high bit is set */ - if ((lparam >> 24 & 0x1)) + 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);