From 324f26cc11899149af058ec1882bade84ec185ea Mon Sep 17 00:00:00 2001 From: hogliux Date: Wed, 10 Jun 2015 10:03:29 +0100 Subject: [PATCH] Fix incorrect key-code translation which could occur for special key-codes in KeyPress::isKeyCurrentlyDown on Windows --- .../native/juce_win32_Windowing.cpp | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 1796de478f..0b55b2ece3 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -2968,24 +2968,27 @@ bool KeyPress::isKeyCurrentlyDown (const int keyCode) { SHORT k = (SHORT) keyCode; - if ((keyCode & extendedKeyModifier) == 0 - && (k >= (SHORT) 'a' && k <= (SHORT) 'z')) - k += (SHORT) 'A' - (SHORT) 'a'; + if ((keyCode & extendedKeyModifier) == 0) + { + if (k >= (SHORT) 'a' && k <= (SHORT) 'z') + k += (SHORT) 'A' - (SHORT) 'a'; - 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 }; + // 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 }; - for (int i = 0; i < numElementsInArray (translatedValues); i += 2) - if (k == translatedValues [i]) - k = translatedValues [i + 1]; + for (int i = 0; i < numElementsInArray (translatedValues); i += 2) + if (k == translatedValues [i]) + k = translatedValues [i + 1]; + } return HWNDComponentPeer::isKeyDown (k); }