Browse Source

Improved OSX realtime key modifier flag detection.

tags/2021-05-28
jules 14 years ago
parent
commit
2ae2f8da30
1 changed files with 12 additions and 5 deletions
  1. +12
    -5
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm

+ 12
- 5
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -227,6 +227,7 @@ public:
static void showArrowCursorIfNeeded(); static void showArrowCursorIfNeeded();
static void updateModifiers (NSEvent* e); static void updateModifiers (NSEvent* e);
static void updateModifiers (NSUInteger);
static void updateKeysDown (NSEvent* ev, bool isKeyDown); static void updateKeysDown (NSEvent* ev, bool isKeyDown);
static int getKeyCodeFromEvent (NSEvent* ev) static int getKeyCodeFromEvent (NSEvent* ev)
@@ -918,18 +919,23 @@ bool KeyPress::isKeyCurrentlyDown (const int keyCode)
return false; return false;
} }
void NSViewComponentPeer::updateModifiers (NSEvent* e)
void NSViewComponentPeer::updateModifiers (const NSUInteger flags)
{ {
int m = 0; 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); currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
} }
void NSViewComponentPeer::updateModifiers (NSEvent* e)
{
updateModifiers ([e modifierFlags]);
}
void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown) void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
{ {
updateModifiers (ev); updateModifiers (ev);
@@ -946,6 +952,7 @@ void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
{ {
NSViewComponentPeer::updateModifiers ([NSEvent modifierFlags]);
return NSViewComponentPeer::currentModifiers; return NSViewComponentPeer::currentModifiers;
} }


Loading…
Cancel
Save