From 2ae2f8da30750ca8cdd8d5ae99db2a7d0dbb5662 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 20 Nov 2011 10:47:21 +0000 Subject: [PATCH] Improved OSX realtime key modifier flag detection. --- .../native/juce_mac_NSViewComponentPeer.mm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index d5c4069762..5218795631 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -227,6 +227,7 @@ public: static void showArrowCursorIfNeeded(); static void updateModifiers (NSEvent* e); + static void updateModifiers (NSUInteger); static void updateKeysDown (NSEvent* ev, bool isKeyDown); static int getKeyCodeFromEvent (NSEvent* ev) @@ -918,18 +919,23 @@ bool KeyPress::isKeyCurrentlyDown (const int keyCode) return false; } -void NSViewComponentPeer::updateModifiers (NSEvent* e) +void NSViewComponentPeer::updateModifiers (const NSUInteger flags) { int m = 0; - if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier; - if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier; - if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier; - if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier; + if ((flags & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier; + if ((flags & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier; + if ((flags & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier; + if ((flags & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier; currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m); } +void NSViewComponentPeer::updateModifiers (NSEvent* e) +{ + updateModifiers ([e modifierFlags]); +} + void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown) { updateModifiers (ev); @@ -946,6 +952,7 @@ void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown) ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept { + NSViewComponentPeer::updateModifiers ([NSEvent modifierFlags]); return NSViewComponentPeer::currentModifiers; }