1

how do I observe keyboard input event while the applicaion is not actived.

xhan
  • 6,057
  • 4
  • 33
  • 47
  • re Ghommeny: good idea. but I just want to user change song by hotkeys and without active my music app. – xhan Aug 24 '10 at 01:50

1 Answers1

3

You'll need to create a CGEventTap using Quartz Event Services. The user must have access for assistive devices turned on, which makes sense, because that's the only legitimate reason for you to do that.

If you want to set up a hotkey, there's an API in Carbon Event Manager for that, and a Cocoa wrapper named SGHotKeysLib. Note that the Carbon Event Manager hotkey API is still supported in current, 64-bit Mac OS X.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • `Carbon` ? is there new api sets in leapord – xhan Aug 24 '10 at 01:51
  • Carbon dates back to 10.0, as noted in the documentation. Most of it is deprecated and/or unavailable now, but some parts are not, and the Carbon Event Manager hotkey API is one of the parts that are still available and supported. – Peter Hosey Aug 24 '10 at 04:58
  • seems its the only way to handle event like this. – xhan Nov 18 '10 at 05:53
  • I know it's too late to answer this but right now i'd go with `NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:` google it, you'll get started. – Pedro Vieira Oct 28 '12 at 14:53
  • @PedroVieira: It's not too late to answer it. – Peter Hosey Oct 28 '12 at 20:52