/
HotkeyHandler.m
55 lines (44 loc) · 1.42 KB
/
HotkeyHandler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// HotkeyHandler.m
// PushPasteMac
//
// Created by Motohiro Takayama on 7/11/09.
// Copyright 2009 deadbeaf.org. All rights reserved.
//
// based on this article: http://cocoasamurai.blogspot.com/2009/03/global-keyboard-shortcuts-with-carbon.html
//
#import <Carbon/Carbon.h>
#import "HotkeyHandler.h"
OSStatus myHotKeyHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData);
@implementation HotkeyHandler
@synthesize daemon;
- (void) setupHotkey
{
EventHotKeyRef myHotKeyRef;
EventHotKeyID myHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&myHotKeyHandler,1,&eventType,self,NULL);
myHotKeyID.signature='mhk1';
myHotKeyID.id=1;
RegisterEventHotKey(49, cmdKey+optionKey, myHotKeyID, GetApplicationEventTarget(), 0, &myHotKeyRef);
}
@end
OSStatus myHotKeyHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData)
{
EventHotKeyID hkRef;
GetEventParameter(anEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkRef),NULL,&hkRef);
HotkeyHandler *hotkey_handler = (HotkeyHandler *)userData;
switch (hkRef.id) {
case 1:
// get clipboard text
// send to iPhone
[hotkey_handler.daemon trigger];
break;
default:
NSLog(@"other events");
break;
}
return noErr;
}