可可:将鼠标限制到屏幕 [英] Cocoa: Limit mouse to screen

查看:236
本文介绍了可可:将鼠标限制到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为OSX开发一个信息亭模式应用程序。在某些情况下,另一个屏幕被附加。我的应用程序在一个屏幕上以全屏模式运行:

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

选项如下:

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

我想要的是将鼠标光标限制在游戏运行的屏幕上。


解决方案

添加一个NSTrackingArea到你的屏幕不想让鼠标进入。当您收到鼠标进入跟踪区域的通知时,使用CGEventCreateMouseEvent和CGPostEvent将鼠标移回到安全的位置,可能是主屏幕上最近的点。


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.

这篇关于可可:将鼠标限制到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆