flagsChanged: not being called on NSControl subclass


Steve Mills
 

What do you have to do these days to make this work? I tried returning YES from acceptsFirstResponder, as was suggested somewhere.

There is 1 NSTrackingArea added to the view, using options NSTrackingCursorUpdate | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag.

isOpaque returns NO.

Not sure what else to try. Just trying to set the cursor when modifiers change.

--
Steve Mills
Drummer, Mac geek


James Walker
 

On 5/17/19 11:22 PM, Steve Mills via Groups.Io wrote:
What do you have to do these days to make this work? I tried returning YES from acceptsFirstResponder, as was suggested somewhere.
There is 1 NSTrackingArea added to the view, using options NSTrackingCursorUpdate | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag.
isOpaque returns NO.
Not sure what else to try. Just trying to set the cursor when modifiers change.

Does your control actually become first responder? That might be necessary for flagsChanged: to go to your control.

A less than perfect option would be to poll the modifier flags on mouse moves.

Another option might be to use +[NSEvent addLocalMonitorForEventsMatchingMask:handler:].

The only case in which I have personal experience with receiving NSFlagsChanged is when I wrote my own local event loop that repeatedly called -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:].


Steve Mills
 

On May 20, 2019, at 11:29, James Walker <list2@jwwalker.com> wrote:

Does your control actually become first responder? That might be necessary for flagsChanged: to go to your control.
Aha! No, it was not. It does now and I’m getting flagsChanged. I guess that makes sense that the OS only sends those to the firstResponder. Thanks for your hunch.

Another option might be to use +[NSEvent addLocalMonitorForEventsMatchingMask:handler:].
Extending your suggestion, I added a global monitor so I could change the cursor in my floating window when the app wasn’t frontmost, but sadly it appears you can’t change the cursor when you’re not the front app, even if the mouse is over your window that’s in front of other apps’ windows. Oh well. The app I’m replacing couldn’t do that either.

Steve via iPhone