So I have a menu bar application that has a slider inside a custom view: I want the ability to press the option key while dragging to make the slider snap to increments.
Right now, everything is working... except I cannot find a single way to notify my menu app that the option key is being pressed. Here's what I've tried:
NSEvent.addGlobalMonitorForEvents
- "Note that your handler will not be called for events that are sent to your own application."
NSEvent.addLocalMonitorForEvents
- "Your handler will not be called for events that are consumed by nested event-tracking loops such as control tracking, menu tracking, or window dragging"
NSApplication.shared.currentEvent
- This dosesn't work because the flagsChanged event isn't handled by the app, so this value is set to another value (mouse button presses).
flagsChanged(with event: NSEvent)
- This doesn't get called. I've set the
viewController
toacceptFirstResponder
as well as resigned the first responder of the view. Also, I've subclassed the view and overriddenflagsChanged
and that hasn't worked.
- This doesn't get called. I've set the
I've tried creating a menu item that has a key like "s" or "p" to trigger an action. But when the "action" gets triggered, the menu bar hides...
So I'm trying to find how I can be notified when the option key is pressed. Is this possible? I can clarify if you have any questions.