aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/MASShortcut.h
diff options
context:
space:
mode:
authorTomáš Znamenáček2014-08-05 11:13:13 +0200
committerTomáš Znamenáček2015-01-07 15:05:11 +0100
commit377b44220f2a4a8b7ffc3eda9e93cf073e8a74da (patch)
treeb83239fd741773451bd9a75480ebe5a276c7d885 /Framework/MASShortcut.h
parenta3a459b4e4e47bf18dccd5dc7f315389346e3d6c (diff)
downloadMASShortcut-377b44220f2a4a8b7ffc3eda9e93cf073e8a74da.tar.bz2
Repackaged the code as a framework and included the demo.
Packaging the code as a framework is mostly just a formality. It doesn’t really change much, it just turns the code into a regular component. What it does change is that the code now has its own Xcode settings, which could make compatibility easier in the long run. Including the demo in the main repository makes it easier to hack on the library, since you can try the changes immediately. It also shows how to bundle the framework into an app that uses it.
Diffstat (limited to 'Framework/MASShortcut.h')
-rw-r--r--Framework/MASShortcut.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/Framework/MASShortcut.h b/Framework/MASShortcut.h
new file mode 100644
index 0000000..c9081a2
--- /dev/null
+++ b/Framework/MASShortcut.h
@@ -0,0 +1,60 @@
+#import <Carbon/Carbon.h>
+#import <AppKit/AppKit.h>
+
+#define MASShortcutChar(char) [NSString stringWithFormat:@"%C", (unsigned short)(char)]
+#define MASShortcutClear(flags) (flags & (NSControlKeyMask | NSShiftKeyMask | NSAlternateKeyMask | NSCommandKeyMask))
+#define MASShortcutCarbonFlags(cocoaFlags) (\
+ (cocoaFlags & NSCommandKeyMask ? cmdKey : 0) | \
+ (cocoaFlags & NSAlternateKeyMask ? optionKey : 0) | \
+ (cocoaFlags & NSControlKeyMask ? controlKey : 0) | \
+ (cocoaFlags & NSShiftKeyMask ? shiftKey : 0))
+
+// These glyphs are missed in Carbon.h
+enum {
+ kMASShortcutGlyphEject = 0x23CF,
+ kMASShortcutGlyphClear = 0x2715,
+ kMASShortcutGlyphDeleteLeft = 0x232B,
+ kMASShortcutGlyphDeleteRight = 0x2326,
+ kMASShortcutGlyphLeftArrow = 0x2190,
+ kMASShortcutGlyphRightArrow = 0x2192,
+ kMASShortcutGlyphUpArrow = 0x2191,
+ kMASShortcutGlyphDownArrow = 0x2193,
+ kMASShortcutGlyphEscape = 0x238B,
+ kMASShortcutGlyphHelp = 0x003F,
+ kMASShortcutGlyphPageDown = 0x21DF,
+ kMASShortcutGlyphPageUp = 0x21DE,
+ kMASShortcutGlyphTabRight = 0x21E5,
+ kMASShortcutGlyphReturn = 0x2305,
+ kMASShortcutGlyphReturnR2L = 0x21A9,
+ kMASShortcutGlyphPadClear = 0x2327,
+ kMASShortcutGlyphNorthwestArrow = 0x2196,
+ kMASShortcutGlyphSoutheastArrow = 0x2198,
+} MASShortcutGlyph;
+
+@interface MASShortcut : NSObject <NSSecureCoding>
+
+@property (nonatomic) NSUInteger keyCode;
+@property (nonatomic) NSUInteger modifierFlags;
+@property (nonatomic, readonly) UInt32 carbonKeyCode;
+@property (nonatomic, readonly) UInt32 carbonFlags;
+@property (nonatomic, readonly) NSString *keyCodeString;
+@property (nonatomic, readonly) NSString *keyCodeStringForKeyEquivalent;
+@property (nonatomic, readonly) NSString *modifierFlagsString;
+@property (nonatomic, readonly) NSData *data;
+@property (nonatomic, readonly) BOOL shouldBypass;
+@property (nonatomic, readonly, getter = isValid) BOOL valid;
+
+- (id)initWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags;
+
++ (MASShortcut *)shortcutWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags;
++ (MASShortcut *)shortcutWithEvent:(NSEvent *)anEvent;
++ (MASShortcut *)shortcutWithData:(NSData *)aData;
+
+- (BOOL)isTakenError:(NSError **)error;
+
+// The following API enable hotkeys with the Option key as the only modifier
+// For example, Option-G will not generate © and Option-R will not paste ®
++ (void)setAllowsAnyHotkeyWithOptionModifier:(BOOL)allow;
++ (BOOL)allowsAnyHotkeyWithOptionModifier;
+
+@end