本文介绍了如何在应用程序窗口不活动时拦截Cocoa中的热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个在执行时不打开窗口的实用程序,它将从热键激活;我读到当前Cocoa没有一个函数,我应该使用一个已弃用的Carbon函数。

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.

没有真正的方法使用全局热可可钥匙?我应该怎么做:等待Cocoa引入一个函数,或者使用碳函数,直到在Cocoa中没有引入类似的函数。

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?

推荐答案

使用。 此功能在64位中支持(注意,它缺少在64位可用性说明中不可用)。

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

NSEvent的新的 addGlobalMonitorForEventsMatchingMask:handler:方法在Snow Leopard是不是实现热键的最简单的方法。首先,它要求用户具有访问辅助设备的权限;此外,它需要你自己检查每个事件,与 RegisterEventHotKey 系统相比,它只调用您的回调函数,当用户按您注册的特定键。

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.

这篇关于如何在应用程序窗口不活动时拦截Cocoa中的热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 00:23