public
Description: A handy OS X menu icon application for launching commands in Terminal.app and iTerm.
Homepage: http://mbcharbonneau.github.com/terminalicious
Clone URL: git://github.com/mbcharbonneau/terminalicious.git
terminalicious / TRMHotkeyManager.m
100755 92 lines (66 sloc) 1.53 kb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// TRMHotkeyManager.m
// Terminalicious
//
// Created by Marc Charbonneau on 6/9/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
 
#import "TRMHotkeyManager.h"
 
@interface TRMHotkeyManager (Private)
 
- (void)_keyPressed;
 
@end
 
OSStatus eventHandler( EventHandlerCallRef nextHandler, EventRef theEvent, void *userData )
{
[[TRMHotkeyManager sharedManager] _keyPressed];
NSLog( @"do stuff" );
return noErr;
}
 
@implementation TRMHotkeyManager
 
#pragma mark API
 
+ (id)sharedManager;
{
static id sharedManager = nil;
 
if ( sharedManager == nil )
sharedManager = [[self alloc] init];
 
return sharedManager;
}
 
- (id)target;
{
return _target;
}
 
- (SEL)action;
{
return _action;
}
 
- (void)setTarget:(id)target;
{
_target = target;
}
 
- (void)setAction:(SEL)action;
{
_action = action;
}
 
#pragma mark NSObject Overrides
 
- (id)init;
{
if ( ![super init] )
return nil;
 
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
 
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
 
InstallApplicationEventHandler( &eventHandler, 1, &eventType, NULL, NULL );
 
gMyHotKeyID.signature = 'htk1';
gMyHotKeyID.id = 1;
 
RegisterEventHotKey( 49, cmdKey+optionKey, gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef );
 
return self;
}
 
@end
 
@implementation TRMHotkeyManager (Private)
 
- (void)_keyPressed;
{
if ( [[self target] respondsToSelector:[self action]] )
[[self target] performSelector:[self action]];
}
 
@end