From 8aa9b012643265bba95ad25923af3d8da9edb614 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 6 Dec 2023 13:39:57 +0000 Subject: [PATCH] KeyPress: Allow isKeyDown to handle dual-symbol keys like =/+, ;/: on Windows --- .../native/juce_Windowing_windows.cpp | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index 52b65d4174..7ac37adb55 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -4757,29 +4757,14 @@ JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder) //============================================================================== bool KeyPress::isKeyCurrentlyDown (const int keyCode) { - auto k = (SHORT) keyCode; - - if ((keyCode & extendedKeyModifier) == 0) + const auto k = [&] { - if (k >= (SHORT) 'a' && k <= (SHORT) 'z') - k += (SHORT) 'A' - (SHORT) 'a'; - - // Only translate if extendedKeyModifier flag is not set - const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA, - (SHORT) '+', VK_OEM_PLUS, - (SHORT) '-', VK_OEM_MINUS, - (SHORT) '.', VK_OEM_PERIOD, - (SHORT) ';', VK_OEM_1, - (SHORT) ':', VK_OEM_1, - (SHORT) '/', VK_OEM_2, - (SHORT) '?', VK_OEM_2, - (SHORT) '[', VK_OEM_4, - (SHORT) ']', VK_OEM_6 }; + if ((keyCode & extendedKeyModifier) != 0) + return keyCode; - for (int i = 0; i < numElementsInArray (translatedValues); i += 2) - if (k == translatedValues[i]) - k = translatedValues[i + 1]; - } + const auto vk = BYTE (VkKeyScan ((WCHAR) keyCode) & 0xff); + return vk != (BYTE) -1 ? vk : keyCode; + }(); return HWNDComponentPeer::isKeyDown (k); }