views:

31

answers:

1

I just read this article on how to create global hotkeys using Carbon events. In the comments the author mentioned, that he wouldn't probably use this technology anymore because it's the 'way to deprecation'. So far, so good.

Now I'm looking for the Cocoa pendant. Does anyone have a hint where to search for it? I tried to google it for a bit but everything I found was the same approach he took.

Thanks
–f

+3  A: 

You can use +[NSEvent addGlobalMonitorForEventsMatchingMask:handler:], but it's not quite the same as the Carbon method. The associated block is invoked for every key event, so you have to write code to only match the one you want. It also only works in Snow Leopard.

Personally, I continue to use Carbon Events for global hotkeys. Apple is deprecating Carbon, but very slowly, and the events component of Carbon will likely be around for a while.

mipadi
+1 for hotkeys, Carbon is still the way to go. Several parts of Carbon (including the stuff for hotkeys) were upgraded to be 64-bit compatible.
Dave DeLong
As many applications have shown through unfortunate experience, custom key handling is hard. If the user is using any non-QWERTY layout, you will get it wrong. NSEvent monitors are the counterpart to CGEventTap, not hotkeys; leave hotkey handling to the Carbon Event Manager. As long as it stays un-deprecated and there's no Cocoa alternative, there's no reason not to. You can use a third-party wrapper class if you really don't want to write Carbon code.
Peter Hosey