I'm trying to use CGAssociateMouseAndMouseCursorPosition(NO) in a program. This disconnects the mouse from the on screen cursor when your application is "in the foreground". Unfortunately it also disconnects it when Mission Control or the application switcher or who knows what else comes up.
So far I know:
So, is there a way to detect when my application is no longer in control, specifically because Mission Control or the switch has taken over? They really expect the mouse to work and I need to restore that association for them.
Open Mission ControlSwipe up with three or four fingers on your trackpad, or double-tap the surface of your Magic Mouse with two fingers. Open the Mission Control app, which is in your Applications folder. Press the Mission Control key on your Apple keyboard or Touch Bar.
To switch between open apps, press Command-Tab. Release the keys when the app you want is selected. To show all the open windows in the current app, Control-click its icon in the Dock, then choose Show All Windows. To browse other app windows, press Tab.
On your Mac, use Mission Control System Preferences to change options and shortcuts for showing and hiding app windows and the desktop. Learn how to use Mission Control. To change these preferences, choose Apple menu > System Preferences, then click Mission Control .
I share your surprise that a global event monitor isn't seeing the events. In a similar situation, I used a Quartz Event Tap for a similar purpose. The Cocoa global event monitor is quite similar to event taps, so I figured it would work.
I put the tap on kCGAnnotatedSessionEventTap
and compared the result from CGEventGetIntegerValueField(event, kCGEventTargetUnixProcessID)
to getpid()
to determine when the events were going to another app (e.g. Mission Control or Exposé). (I disable the tab when my app resigns active status, so it should only receive events destined for another app when this sort of overlay UI is presented.)
By the way, you mentioned monitoring the default notification center, but, if there's a notification about Mission Control or the like, it's more likely to come to the distributed notification center (NSDistributedNotificationCenter
). So, it's worth checking that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With