开发者

Cocoa: Limit mouse to screen

开发者 https://www.devze.com 2023-01-30 22:50 出处:网络
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:

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消