• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

addGlobalMonitorForEventsMatchingMask在某些计算机上不工作

用户头像
it1352
帮助1

问题说明

我使用这个代码在我的应用程序中捕获全局键盘快捷键。

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) {

正确答案

#1

在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
系列文章
更多 icon
同类精品
更多 icon
继续加载