English 中文(简体)
How to intercept a hot key in Cocoa when the application window is not active
原标题:

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?

最佳回答

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.

问题回答

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.





相关问题
Implementing Centralized Hotkey Handling/Processing

I m working on a project where I need to implement customizable hotkeys across the application. There are a number of different forms and user controls that need to implement different subsets of ...

Disable HotKeys When Typing - VB6

In my VB6 program, I have tons of hotkeys such as X, A, D... ETC . I also have a chat system in it, where everytime I use the characters X or A it will do the actions of those hotkeys. For example, if ...

Adding an F5 Hotkey in C#

I m making a windows app (WinForms) and would like my application to call a method when the user presses F5 - this should work no matter what the user is doing but they must be using the program - I ...

Need a cool hotkey for my hidden website-login

I am developing a CMS. One of the greatest everyday annoyances when working with it is that when you are on a front-end page, not logged in, and want to make a change, you need to go to the back-end ...

热门标签