From 4718026b47c3d34dcfe659b847287ba4651e8a0e Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 13 Jul 2012 18:17:25 +0100 Subject: [PATCH] OSX keycode character fix. --- .../native/juce_mac_NSViewComponentPeer.mm | 34 ++++++++++++++----- .../windows/juce_ComponentPeer.cpp | 5 ++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 2f89bb942a..2520e5c242 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -578,26 +578,42 @@ public: bool handleKeyEvent (NSEvent* ev, bool isKeyDown) { - String unicode (nsStringToJuce ([ev characters])); - String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers])); - int keyCode = getKeyCodeFromEvent (ev); + const String unicode (nsStringToJuce ([ev characters])); + const int keyCode = getKeyCodeFromEvent (ev); //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0])); + //String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers])); //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0])); - if (unicode.isNotEmpty() || keyCode != 0) + if (keyCode != 0 || unicode.isNotEmpty()) { if (isKeyDown) { bool used = false; - while (unicode.length() > 0) + for (String::CharPointerType u (unicode.getCharPointer()); ! u.isEmpty();) { - juce_wchar textCharacter = unicode[0]; - unicode = unicode.substring (1); + juce_wchar textCharacter = u.getAndAdvance(); - if (([ev modifierFlags] & NSCommandKeyMask) != 0) - textCharacter = 0; + switch (keyCode) + { + case NSLeftArrowFunctionKey: + case NSRightArrowFunctionKey: + case NSUpArrowFunctionKey: + case NSDownArrowFunctionKey: + case NSPageUpFunctionKey: + case NSPageDownFunctionKey: + case NSEndFunctionKey: + case NSHomeFunctionKey: + case NSDeleteFunctionKey: + textCharacter = 0; + break; // (these all seem to generate unwanted garbage unicode strings) + + default: + if (([ev modifierFlags] & NSCommandKeyMask) != 0) + textCharacter = 0; + break; + } used = handleKeyUpOrDown (true) || used; used = handleKeyPress (keyCode, textCharacter) || used; diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp index caffac5502..9e9d8f1f63 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp @@ -135,8 +135,7 @@ void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo) jassert (roundToInt (10.1f) == 10); } -bool ComponentPeer::handleKeyPress (const int keyCode, - const juce_wchar textCharacter) +bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter) { updateCurrentModifiers(); @@ -186,7 +185,7 @@ bool ComponentPeer::handleKeyPress (const int keyCode, if (currentlyFocused != nullptr) { - const bool isTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::noModifiers, 0)); + const bool isTab = (keyInfo == KeyPress::tabKey); const bool isShiftTab = (keyInfo == KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier, 0)); if (isTab || isShiftTab)