Created
October 20, 2016 11:18
-
-
Save JFKingsley/f85dc1bb566c946423435e311f6dde0c to your computer and use it in GitHub Desktop.
Global hotkey registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gMyHotKeyID = EventHotKeyID() | |
gMyHotKeyID.signature = OSType("swat".fourCharCodeValue) | |
gMyHotKeyID.id = UInt32(keyCode) | |
var eventType = EventTypeSpec() | |
eventType.eventClass = OSType(kEventClassKeyboard) | |
eventType.eventKind = OSType(kEventHotKeyPressed) | |
// Install handler. | |
InstallEventHandler(GetApplicationEventTarget(), {(nextHanlder, theEvent, userData) -> OSStatus in | |
var hkCom = EventHotKeyID() | |
GetEventParameter(theEvent, EventParamName(kEventParamDirectObject), EventParamType(typeEventHotKeyID), nil, sizeof(EventHotKeyID), nil, &hkCom) | |
/// Check that hkCom in indeed your hotkey ID and handle it. | |
}, 1, &eventType, nil, nil) | |
// Register hotkey. | |
let status = RegisterEventHotKey(UInt32(keyCode), UInt32(modifierKeys), gMyHotKeyID, GetApplicationEventTarget(), 0, &hotKeyRef) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment