Skip to content

Instantly share code, notes, and snippets.

@willemvds
Created October 15, 2014 18:45
Show Gist options
  • Save willemvds/6bec2b26a9a35aa668e1 to your computer and use it in GitHub Desktop.
Save willemvds/6bec2b26a9a35aa668e1 to your computer and use it in GitHub Desktop.
Global hotkey stuff using carbon example code.
What is OSX? What is Obj-c? Who am I?
.h
#import <Carbon/Carbon.h>
.m
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler, 1, &eventType, NULL, NULL);
gMyHotKeyID.signature = "whoknows1";
gMyHotKeyID.id = 1;
RegisterEventHotKey(49, NULL, gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData)
{
printf("So like the key was pressed or something?\n");
return noErr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment