Skip to content

Commit b5b2bae

Browse files
committed
optimize
1 parent 6cb0621 commit b5b2bae

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

Sources/OpenKey/macOS/ModernKey/OpenKey.mm

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
#define EMPTY_HOTKEY 0xFE0000FE
2222
#define LOAD_DATA(VAR, KEY) VAR = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@#KEY]
2323

24+
// Ignore code for Modifier keys and numpad
25+
// Reference: https://eastmanreference.com/complete-list-of-applescript-key-codes
26+
NSDictionary *keyStringToKeyCodeMap = @{
27+
// Characters from number row
28+
@"`": @50, @"~": @50, @"1": @18, @"!": @18, @"2": @19, @"@": @19, @"3": @20, @"#": @20, @"4": @21, @"$": @21,
29+
@"5": @23, @"%": @23, @"6": @22, @"^": @22, @"7": @26, @"&": @26, @"8": @28, @"*": @28, @"9": @25, @"(": @25,
30+
@"0": @29, @")": @29, @"-": @27, @"_": @27, @"=": @24, @"+": @24,
31+
// Characters from first keyboard row
32+
@"q": @12, @"w": @13, @"e": @14, @"r": @15, @"t": @17, @"y": @16, @"u": @32, @"i": @34, @"o": @31, @"p": @35,
33+
@"[": @33, @"{": @33, @"]": @30, @"}": @30, @"\\": @42, @"|": @42,
34+
// Characters from second keyboard row
35+
@"a": @0, @"s": @1, @"d": @2, @"f": @3, @"g": @5, @"h": @4, @"j": @38, @"k": @40, @"l": @37,
36+
@";": @41, @":": @41, @"'": @39, @"\"": @39,
37+
// Characters from second third row
38+
@"z": @6, @"x": @7, @"c": @8, @"v": @9, @"b": @11, @"n": @45, @"m": @46,
39+
@",": @43, @"<": @43, @".": @47, @">": @47, @"/": @44, @"?": @44
40+
};
41+
2442
extern ViewController* viewController;
2543

2644
extern AppDelegate* appDelegate;
@@ -535,23 +553,6 @@ int ConvertKeyStringToKeyCode(NSString *keyString, CGKeyCode fallback) {
535553
return fallback;
536554
}
537555

538-
// Ignore code for Modifier keys and numpad
539-
// Reference: https://eastmanreference.com/complete-list-of-applescript-key-codes
540-
NSDictionary *keyStringToKeyCodeMap = @{
541-
// Characters from number row
542-
@"`": @50, @"~": @50, @"1": @18, @"!": @18, @"2": @19, @"@": @19, @"3": @20, @"#": @20, @"4": @21, @"$": @21,
543-
@"5": @23, @"%": @23, @"6": @22, @"^": @22, @"7": @26, @"&": @26, @"8": @28, @"*": @28, @"9": @25, @"(": @25,
544-
@"0": @29, @")": @29, @"-": @27, @"_": @27, @"=": @24, @"+": @24,
545-
// Characters from first keyboard row
546-
@"q": @12, @"w": @13, @"e": @14, @"r": @15, @"t": @17, @"y": @16, @"u": @32, @"i": @34, @"o": @31, @"p": @35,
547-
@"[": @33, @"{": @33, @"]": @30, @"}": @30, @"\\": @42, @"|": @42,
548-
// Characters from second keyboard row
549-
@"a": @0, @"s": @1, @"d": @2, @"f": @3, @"g": @5, @"h": @4, @"j": @38, @"k": @40, @"l": @37,
550-
@";": @41, @":": @41, @"'": @39, @"\"": @39,
551-
// Characters from second third row
552-
@"z": @6, @"x": @7, @"c": @8, @"v": @9, @"b": @11, @"n": @45, @"m": @46,
553-
@",": @43, @"<": @43, @".": @47, @">": @47, @"/": @44, @"?": @44
554-
};
555556
NSNumber *keycode = [keyStringToKeyCodeMap objectForKey:lowercasedKeyString];
556557

557558
if (keycode) {

0 commit comments

Comments
 (0)