Cocoa:限制鼠标在屏幕上
我正在为 OSX 开发一个信息亭模式应用程序。在某些情况下,会连接另一个屏幕。我的应用程序在一个屏幕上全屏运行,使用:
[self.window.contentView enterFullScreenMode:s
withOptions:[NSDictionary dictionaryWithObject:appOptions
forKey:NSFullScreenModeApplicationPresentationOptions]];
选项如下:
[NSNumber numberWithUnsignedInt:(NSApplicationPresentationHideMenuBar|
NSApplicationPresentationHideDock|
NSApplicationPresentationDisableHideApplication|
NSApplicationPresentationDisableProcessSwitching|
NSApplicationPresentationDisableAppleMenu)];
我想要的是将鼠标光标限制在游戏运行的屏幕上。
我怎样才能做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 NSTrackingArea 添加到您不希望鼠标进入的屏幕。当您收到鼠标已进入跟踪区域的通知时,请使用 CGEventCreateMouseEvent 和 CGPostEvent 将鼠标移回安全位置,可能是主屏幕上最近的点。
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.