From 8d59442ab05c870b60e98cd07711af4c6a9143c2 Mon Sep 17 00:00:00 2001 From: houmain Date: Fri, 24 Jun 2022 17:39:36 +0200 Subject: [PATCH] Improved Pause/NumLock key handling on Windows --- src/server/windows/main.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/server/windows/main.cpp b/src/server/windows/main.cpp index 4fbd216..95a745e 100644 --- a/src/server/windows/main.cpp +++ b/src/server/windows/main.cpp @@ -55,15 +55,15 @@ namespace { key.ki.dwFlags |= (event.state == KeyState::Up ? KEYEVENTF_KEYUP : 0); key.ki.time = GetTickCount(); - // special handling of ShiftRight - if (event.key == Key::ShiftRight) { - key.ki.wVk = VK_RSHIFT; - } - else { - key.ki.dwFlags |= KEYEVENTF_SCANCODE; - if (*event.key & 0xE000) - key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; - key.ki.wScan = static_cast(event.key); + switch (event.key) { + case Key::ShiftRight: key.ki.wVk = VK_RSHIFT; break; + case Key::Pause: key.ki.wVk = VK_PAUSE; break; + case Key::NumLock: key.ki.wVk = VK_NUMLOCK; break; + default: + key.ki.dwFlags |= KEYEVENTF_SCANCODE; + if (*event.key & 0xE000) + key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; + key.ki.wScan = static_cast(event.key); } return key; } @@ -222,13 +222,19 @@ namespace { if (!kbd.scanCode || injected || g_sending_key) return false; - const auto input = get_key_event(wparam, kbd); + auto input = get_key_event(wparam, kbd); // intercept ControlRight preceding AltGr const auto ControlRightPrecedingAltGr = 0x21D; if (*input.key == ControlRightPrecedingAltGr) return true; + // turn NumLock succeeding Pause into another Pause + if (input.state == g_last_key_event.state && + input.key == Key::NumLock && + g_last_key_event.key == Key::Pause) + input.key = Key::Pause; + return translate_input(input); }