Skip to content

Commit

Permalink
KeyPress: Allow isKeyDown to handle dual-symbol keys like =/+, ;/: on…
Browse files Browse the repository at this point in the history
… Windows
  • Loading branch information
reuk committed Dec 7, 2023
1 parent 224c4f7 commit 8aa9b01
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions modules/juce_gui_basics/native/juce_Windowing_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8aa9b01

Please sign in to comment.