当应用程序窗口不活动时如何拦截Cocoa中的热键

发布于 2024-08-15 05:37:44 字数 170 浏览 4 评论 0原文

我正在尝试创建一个实用程序,该实用程序在执行时不会打开窗口,并且可以通过热键激活;我读到目前 Cocoa 没有相应的函数,我应该使用已弃用的 Carbon 函数。

难道Cocoa真的没有办法使用全局热键吗?我该怎么办:等待Cocoa为此引入一个函数,或者使用carbon函数直到Cocoa中没有引入类似的函数?

I am trying to create a utility that doesn't open a window when executed, and that would be activated from a hot key; I read that currently Cocoa doesn't have a function for that, and that I should use a deprecated Carbon function.

Isn't there really a way to use global hot keys in Cocoa? What should I do: wait for Cocoa to introduce a function for that, or use the carbon function until a similar function is not introduced in Cocoa?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡月浅 2024-08-22 05:37:44

使用 Carbon 事件管理器的 RegisterEventHotKey 函数此函数在 64 位中受支持(请注意,它缺少“在 64 位中不可用”可用性说明)。

相反,Snow Leopard 中 NSEvent 的新 addGlobalMonitorForEventsMatchingMask:handler: 方法不是实现热键的最简单方法。一方面,它要求用户能够访问打开的辅助设备;此外,它要求您自己检查每个事件,而 RegisterEventHotKey 系统仅在用户按下您注册的特定键时调用您的回调函数。

Use the Carbon Event Manager's RegisterEventHotKey function. This function is supported in 64-bit (notice that it lacks the “not available in 64-bit” availability note).

Conversely, NSEvent's new addGlobalMonitorForEventsMatchingMask:handler: method in Snow Leopard is not the easiest way to implement a hot-key. For one thing, it requires that the user have access for assistive devices turned on; moreover, it requires you to examine every event yourself, as compared with the RegisterEventHotKey system, which only calls your callback function when the user presses the specific key you registered for.

挽梦忆笙歌 2024-08-22 05:37:44

看一下 Shortcut Recorder (http://wafflesoftware.net/shortcut/),它是一个使用全局热键的 Carbon 事件管理器还允许您更改用户来更改热键(如果这是您想要的)。

并查看此项目/代码以了解如何实现它:http://github.com/sdegutis/SDGlobalShortcuts

Take a look at Shortcut Recorder (http://wafflesoftware.net/shortcut/) a framework that uses the Carbon Event Manager for Global Hotkeys it also allows you to change the user to change the HotKey (if this is what you want).

And see this Project/Code on how to implement it : http://github.com/sdegutis/SDGlobalShortcuts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文