addGlobalMonitorForEventsMatchingMask在某些计算机上不工作
问题说明
我使用这个代码在我的应用程序中捕获全局键盘快捷键。
I'm using this code to capture Global Keyboard Shortcuts in my app.
这几乎在我运行它的每台计算机上都工作得很好。我试了一个全新的Retina Macbook Pro本周, addGlobalMonitorForEventsMatchingMask
根本不工作。它甚至不记录每个键,像我已经设置为这里做调试。
This works great on almost every computer I run it on. I tried it on a brand new Retina Macbook Pro this week and addGlobalMonitorForEventsMatchingMask
doesn't work at all. It doesn't even log every key like I have it set up to do here for debugging.
有更可靠的方法吗?现在我加载到 applicationDidFinishLaunching
。
Is there a more reliable way to do this? Right now I load this on applicationDidFinishLaunching
.
我认为加载它作为自己的方法更有意义在App Delegate中,但我不知道它的语法将是什么样子。
I think it might make more sense to load it as its own method in the App Delegate but I'm not sure what the syntax of that would look like.
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event){
NSLog(@"sequence = %li", (unsigned long)[event modifierFlags]);
// Activate app when pressing cmd-c
if([event modifierFlags] == 1048840 && [[event charactersIgnoringModifiers] compare:@"c"] == 0) {
正确答案
在OSX 10.9(Mavericks)到系统首选项>安全&隐私权>隐私权>辅助功能 - 请确保您的应用已被选中。
In OSX 10.9 (Mavericks) the setting has moved to System Preferences > Security & Privacy > Privacy > Accessibility - make sure your app is checked.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcakkce
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
复制文件夹/文件而不修改属性?
it1352 07-15 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20