I'm using this code to capture Global Keyboard Shortcuts in my app.
我用这段代码在我的应用中捕获全局快捷键。
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.
这在我运行的几乎每一台电脑上都很好用。本周,我试用了一款全新的Retina Macbook Pro笔记本电脑,而addGlobalMonitorForEventsMatchingMask根本不起作用。它甚至不像我在这里设置的那样记录每个键来进行调试。
Is there a more reliable way to do this? Right now I load this on applicationDidFinishLaunching
.
有没有更可靠的方法?现在我将这个加载到applicationDidFinishLaunching。
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.
我认为把它作为自己的方法加载到App委托中会更有意义,但我不确定它的语法是什么样子的。
[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) {
2 个解决方案
#1
8
In OSX 10.9 (Mavericks) the setting has moved to System Preferences > Security & Privacy > Privacy > Accessibility - make sure your app is checked.
在osx10.9 (Mavericks)中,设置已转移到系统首选项>安全和隐私> >隐私>可访问性——确保检查你的应用。
#2
0
check the "Enable access for assistive devies" in accessiblity in system prefrences and try again.
检查系统中可访问性中的“辅助异常的启用访问”,然后再试一次。
#1
8
In OSX 10.9 (Mavericks) the setting has moved to System Preferences > Security & Privacy > Privacy > Accessibility - make sure your app is checked.
在osx10.9 (Mavericks)中,设置已转移到系统首选项>安全和隐私> >隐私>可访问性——确保检查你的应用。
#2
0
check the "Enable access for assistive devies" in accessiblity in system prefrences and try again.
检查系统中可访问性中的“辅助异常的启用访问”,然后再试一次。