-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYShortcutActuator.h
127 lines (100 loc) · 4.14 KB
/
SSYShortcutActuator.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#import <Cocoa/Cocoa.h>
#import "SRCommon.h" // for KeyCombo, also this imports <Carbon/Carbon.h>
/*
@brief Posted whenever the count of shortcuts registered with the shared
actuator increases from 0 to 1
@details The notification object is the shared actuator. If the user defaults
contains one or more shortcuts to be registered, this notification will be
posted during the -init of the shared actuator.
*/
extern NSString* const SSYShortcutActuatorDidNonemptyNotification ;
/*
@brief Posted whenever the count of shortcuts registered with the shared
actuator decreases from 1 to 0
@details The notification object is the shared actuator.
*/
extern NSString* const SSYShortcutActuatorDidEmptyNotification ;
/*
@brief Posted at the conclusion of -setKeyCode:modifierFlags:selectorName:,
whether or not any shortcut was actually registered or unregistered
@details The notification object is the actuator to which
-setKeyCode:modifierFlags:selectorName: was sent.
*/
extern NSString* const SSYShortcutActuatorDidChangeShortcutsNotification ;
@interface SSYShortcutActuator : NSObject {
NSMutableDictionary* m_registeredShortcutInfos ;
NSMutableDictionary* m_selectorNameLookup ;
NSUInteger m_shortcutSerialNumber ;
BOOL m_isHandlerInstalled ;
}
/*
@brief Returns a key path in the application's shared user defaults
controller in which the key binding for a given selector name is stored.
@details This is useful if you want to observe changes in key bindings
with key value observing.
*/
+ (NSString*)userDefaultsKeyPathForSelectorName:(NSString*)selectorName ;
/*!
@brief
@details This function was written by Harry Jordan of
Inquisitive Software, Brighton, UK, http://inquisitivesoftware.com/
Specifically, it was ripped from
http://inquisitivecocoa.com/2009/04/05/key-code-translator/
@param keyCode
@param modifierFlags
*/
+ (NSString*)stringForKeyCode:(NSInteger)keyCode
modifierFlags:(NSUInteger)modifierFlags ;
/*!
@brief Returns a human-readable ASCII description of a modifiers
key number, for example "cmd+opt+ctrl+shift+func"
@details This is intended for debugging; it is not localized.
*/
+ (NSString*)descriptionOfModifiers:(NSUInteger)modifiers ;
/*!
@brief Creates if not yet existing, and then returns the
shared actuator for this application.
@details Even if there are no shortcuts to be set or removed,
if you want shortcuts which were remembered in the app's user
defaults to be installed and work, you should invoke this
method.
*/
+ (SSYShortcutActuator*)sharedActuator ;
/*!
@brief Installs a Carbon Event handler for a given shortcut
key combination to a given selector in [NSApp delegate], and
also registers this combination and selector in standard user
defaults, so that it will be installed whenever the shared
actuator is created, typically whenever this app is relaunched.
@details
@param keyCode The key code for the new handler, or -1
to remove the handler
@param modifierFlags The Cocoa modifier keys for the new handler, for
example NSEventModifierFlagShift+NSEventModifierFlagCommand+NSEventModifierFlagOption+NSEventModifierFlagControl
@param selectorName The name of the selector of the message which
will be sent to [NSApp delegate], if it responds, when the user
presses the shortcut. This selector's signature must take 0 parameters.
*/
- (void)setKeyCode:(NSInteger)keyCode
modifierFlags:(NSUInteger)modifierFlags
selectorName:(NSString*)selectorName ;
/*!
@brief Returns the KeyCombo of the shortcut which is currently registered to
invoke a give selector
@details If no such shortcut is currently registered, the 'code' member of
the result is -1. Or use -hasKeyComboForSelectorName: instead.
*/
- (KeyCombo)keyComboForSelectorName:(NSString*)selectorName ;
/*!
@brief Returns whether or not a keyboard shortcut is currently registered
to invoke a given selector
*/
- (BOOL)hasKeyComboForSelectorName:(NSString*)selectorName ;
/*!
@brief Returns whether or not the receiver has one or more keyboard
shortcuts currently registered
*/
- (BOOL)hasAnyKeyCombo ;
- (void)disableAllShortcuts ;
- (void)enableAllShortcuts ;
@end