forked from octiplex/ShortcutRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRCommon.m
51 lines (42 loc) · 1.77 KB
/
SRCommon.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
//
// SRCommon.m
// ShortcutRecorder
//
// Copyright 2006-2012 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick
// Andy Kim
// Ilya Kulakov
#import "SRCommon.h"
#import "SRKeyCodeTransformer.h"
NSString *SRReadableStringForCocoaModifierFlagsAndKeyCode(NSUInteger aModifierFlags, unsigned short aKeyCode)
{
SRKeyCodeTransformer *t = [SRKeyCodeTransformer sharedPlainTransformer];
NSString *c = [t transformedValue:@(aKeyCode)];
if (![t isKeyCodeSpecial:aKeyCode])
c = [c uppercaseString];
return [NSString stringWithFormat:@"%@%@%@%@%@",
(aModifierFlags & NSCommandKeyMask ? SRLoc(@"Command-") : @""),
(aModifierFlags & NSAlternateKeyMask ? SRLoc(@"Option-") : @""),
(aModifierFlags & NSControlKeyMask ? SRLoc(@"Control-") : @""),
(aModifierFlags & NSShiftKeyMask ? SRLoc(@"Shift-") : @""),
c];
}
NSString *SRReadableASCIIStringForCocoaModifierFlagsAndKeyCode(NSUInteger aModifierFlags, unsigned short aKeyCode)
{
SRKeyCodeTransformer *t = [SRKeyCodeTransformer sharedPlainASCIITransformer];
NSString *c = [t transformedValue:@(aKeyCode)];
if (![t isKeyCodeSpecial:aKeyCode])
c = [c uppercaseString];
return [NSString stringWithFormat:@"%@%@%@%@%@",
(aModifierFlags & NSCommandKeyMask ? SRLoc(@"Command-") : @""),
(aModifierFlags & NSAlternateKeyMask ? SRLoc(@"Option-") : @""),
(aModifierFlags & NSControlKeyMask ? SRLoc(@"Control-") : @""),
(aModifierFlags & NSShiftKeyMask ? SRLoc(@"Shift-") : @""),
c];
}