4

I'm developing a kiosk mode application for OSX. In some circumstances, another screen gets attached. My application runs in fullscreen on one screen using:

[self.window.contentView enterFullScreenMode:s 
                                 withOptions:[NSDictionary dictionaryWithObject:appOptions
                                      forKey:NSFullScreenModeApplicationPresentationOptions]];

The options are the following:

[NSNumber numberWithUnsignedInt:(NSApplicationPresentationHideMenuBar|
                                NSApplicationPresentationHideDock|
                                 NSApplicationPresentationDisableHideApplication|
                                 NSApplicationPresentationDisableProcessSwitching|
                                 NSApplicationPresentationDisableAppleMenu)];

What I want is limit the mouse cursor to the screen where the game is running.

How can I accomplish that?

jsadfeew
  • 2,247
  • 1
  • 18
  • 25

1 Answers1

8

Add an NSTrackingArea to the screens you don't want the mouse entering. When you get notified that the mouse has entered the tracking area, use CGEventCreateMouseEvent and CGPostEvent to move the mouse back to a safe location, probably the nearest point on the main screen.

BJ Homer
  • 48,806
  • 11
  • 116
  • 129
  • 2
    Sounds good - I'll try your idea flipped - trapping mouseExited-events. – jsadfeew Dec 17 '10 at 15:35
  • Good call; that will work better anyway since you have to add tracking areas to a view, not just to arbitrary screen coordinates. I'd forgotten that. – BJ Homer Dec 17 '10 at 15:51