From db75b3e5cf7490f48f204be018521b684115f8e7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 2 Sep 2024 19:52:18 -0500 Subject: [PATCH] fix(win/input): use active keyboard layout for non-normalized key events --- src/platform/windows/input.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/platform/windows/input.cpp b/src/platform/windows/input.cpp index 5ff61689106..ea0551746cd 100644 --- a/src/platform/windows/input.cpp +++ b/src/platform/windows/input.cpp @@ -618,12 +618,16 @@ namespace platf { auto &ki = i.ki; // If the client did not normalize this VK code to a US English layout, we can't accurately convert it to a scancode. - bool send_scancode = !(flags & SS_KBE_FLAG_NON_NORMALIZED) || config::input.always_send_scancodes; - - if (send_scancode) { + // If we're set to always send scancodes, we will use the current keyboard layout to convert to a scancode. This will + // assume the client and host have the same keyboard layout, but it's probably better than always using US English. + if (!(flags & SS_KBE_FLAG_NON_NORMALIZED)) { // Mask off the extended key byte ki.wScan = VK_TO_SCANCODE_MAP[modcode & 0xFF]; } + else if (config::input.always_send_scancodes && modcode != VK_LWIN && modcode != VK_RWIN && modcode != VK_PAUSE) { + // For some reason, MapVirtualKey(VK_LWIN, MAPVK_VK_TO_VSC) doesn't seem to work :/ + ki.wScan = MapVirtualKey(modcode, MAPVK_VK_TO_VSC); + } // If we can map this to a scancode, send it as a scancode for maximum game compatibility. if (ki.wScan) {