Cocoa: screen mouse limitation

I am developing a kiosk mode application for OSX. In some cases, a different screen is connected. My application runs in full screen on one screen using:

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

The following options are possible:

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

I want to limit the mouse cursor to the screen on which the game is running.

How can i do this?

+3
source share
1 answer

Add NSTrackingArea to screens you don’t want to enter the mouse into. When you receive a notification that the mouse has entered the tracking area, use CGEventCreateMouseEvent and CGPostEvent to move the mouse back to a safe place, possibly the closest point on the main screen.

+6
source

Source: https://habr.com/ru/post/1381960/


All Articles