SameBoy/Cocoa/NSString+StringForKey.m

36 lines
1.1 KiB
Mathematica
Raw Normal View History

2016-04-13 19:43:16 +00:00
#import "NSString+StringForKey.h"
#import "KeyboardShortcutPrivateAPIs.h"
#import <Carbon/Carbon.h>
2016-04-13 19:43:16 +00:00
@implementation NSString (StringForKey)
+ (NSString *) displayStringForKeyString: (NSString *)key_string
{
return [[NSKeyboardShortcut shortcutWithKeyEquivalent:key_string modifierMask:0] localizedDisplayName];
}
+ (NSString *) displayStringForKeyCode:(unsigned short) keyCode
{
/* These cases are not handled by stringForVirtualKey */
switch (keyCode) {
case 115: return @"↖";
case 119: return @"↘";
case 116: return @"⇞";
case 121: return @"⇟";
case 51: return @"⌫";
case 117: return @"⌦";
case 76: return @"⌤";
/* Label Keypad buttons accordingly */
default:
if ((keyCode < 82 || keyCode > 92)) {
return [NSPrefPaneUtils stringForVirtualKey:keyCode modifiers:0];
}
case 65: case 67: case 69: case 75: case 78: case 81:
return [@"Keypad " stringByAppendingString:[NSPrefPaneUtils stringForVirtualKey:keyCode modifiers:0]];
}
}
2016-04-13 19:43:16 +00:00
@end