Skip to content

Instantly share code, notes, and snippets.

@isaac
Created May 19, 2009 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaac/114372 to your computer and use it in GitHub Desktop.
Save isaac/114372 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
@interface Shortcut : NSObject
@end
OSStatus myHotKeyHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData);
@implementation Shortcut
- (void)addShortcut
{
EventHotKeyRef myHotKeyRef;
EventHotKeyID myHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&myHotKeyHandler,1,&eventType,NULL,NULL);
myHotKeyID.signature='mhk1';
myHotKeyID.id=1;
RegisterEventHotKey(49, cmdKey+optionKey, myHotKeyID, GetApplicationEventTarget(), 0, &myHotKeyRef);
}
@end
OSStatus myHotKeyHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData)
{
NSLog(@"YEAY WE DID A GLOBAL HOTKEY");
return noErr;
}
void Init_shortcut(void) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment