Cocoa全局快捷键? [英] Cocoa global shortcuts?

查看:198
本文介绍了Cocoa全局快捷键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程式建立一个全域捷径。我使用了'cool new way'这样做与addGlobalMonitorForEventsMatchingMask方法。问题是,我的事件没有得到消耗:我的快捷方式包括空格键,所以每当我使用快捷方式,Quicklook在我在Finder中弹出。

I want to create a global shortcut for my app. I've used the 'cool new way' of doing this with the addGlobalMonitorForEventsMatchingMask method. The problem is, my events don't get "consumed": my shortcut includes the spacebar, so whenever I use the shortcut, Quicklook pops up when I'm in the Finder.

如何防止这种情况发生?我知道这是可能的,因为许多应用程序,例如Bowtie iTunes控制器应用程序。

How can I prevent this from happening? I know it's possible, because many apps, for example the Bowtie iTunes controller app, do it.

推荐答案

addGlobalMonitorForEventsMatchingMask:由于各种原因不适合替代现有的Carbon Hotkey API;它是可怕的低效率,一个。从文档:

addGlobalMonitorForEventsMatchingMask: is not a suitable replacement for the existing Carbon Hotkey API for all sorts of reasons; it's horribly inefficient, for one. And from the docs:


...你只能观察事件;您不能修改或以其他方式阻止该事件传递到其原始目标应用程序。

... you can only observe the event; you cannot modify or otherwise prevent the event from being delivered to its original target application.


只有启用辅助功能或者您的应用程序信任访问辅助功能才能监控与键相关的事件

Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access

Hotkey API仍是在OS X中实现全局快捷方式的唯一方法。但是与许多Carbon API不同,Hotkey API可用于64位应用程序。

The Hotkey API is still the only way to implement global shortcut in OS X. But unlike many Carbon APIs, the Hotkey API is available to 64-bit apps.

这篇关于Cocoa全局快捷键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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