Search code examples
objective-cmacoscocoahotkeys

Register Hotkey


How would I register a global hotkey in Objective-C/Cocoa (Mac) ?

For example, the hotkey I'd like to register would be Alt - Cmd - D

Any help would be appreciated!


Solution

  • There's a convenient Cocoa wrapper for the required Carbon functions on GitHub: JFHotkeyManager. You could also use the new (since 10.6) NSEvent API addGlobalMonitorForEventsMatchingMask:handler:, but it only gets key events if access for assistive devices is enabled.