Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion keycastr/KCDefaultVisualizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "KCDefaultVisualizer.h"
#import "KCKeystroke.h"
#import "KCMouseEvent.h"
#import "KCEventTransformer.h"
#import "NSBezierPath+RoundedRect.h"
#import "NSUserDefaults+Utility.h"

Expand Down Expand Up @@ -193,6 +194,7 @@ - (void)noteFlagsChanged:(NSEventModifierFlags)flags
requiringSecureCoding:NO
error:NULL],
@"default_displayModifiedCharacters": @NO,
@"default.showWindowsEquivalent": @NO,
};
}

Expand Down Expand Up @@ -316,7 +318,18 @@ - (void)addKeystroke:(KCKeystroke *)keystroke
[self abandonCurrentBezelView];
}

[self appendString:[keystroke convertToString]];
NSString *macString = [keystroke convertToString];
BOOL showWindowsEquivalent = [[NSUserDefaults standardUserDefaults] boolForKey:@"default.showWindowsEquivalent"];

NSString *displayString = macString;
if (showWindowsEquivalent) {
NSString *winString = [[KCEventTransformer currentTransformer] transformedValueForWindows:keystroke];
if (winString.length > 0) {
displayString = [NSString stringWithFormat:@"%@ | %@", macString, winString];
}
}

[self appendString:displayString];
}

- (void)appendString:(NSString *)string
Expand Down
51 changes: 32 additions & 19 deletions keycastr/KCDefaultVisualizer.nib/designable.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified keycastr/KCDefaultVisualizer.nib/keyedobjects.nib
Binary file not shown.
2 changes: 2 additions & 0 deletions keycastr/KCEventTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@

- (id)transformedValue:(KCKeycastrEvent *)event;

- (NSString *)transformedValueForWindows:(KCKeycastrEvent *)event;

@end
43 changes: 43 additions & 0 deletions keycastr/KCEventTransformer.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,49 @@ - (id)transformedValue:(KCKeycastrEvent *)event
return mutableResponse;
}

- (NSString *)transformedValueForWindows:(KCKeycastrEvent *)event {
if (![event isKindOfClass:[KCKeystroke class]]) {
return nil;
}

KCKeystroke *keystroke = (KCKeystroke *)event;
NSEventModifierFlags modifiers = event.modifierFlags;

BOOL isCommand = (modifiers & NSEventModifierFlagCommand) != 0;
BOOL isControl = (modifiers & NSEventModifierFlagControl) != 0;
BOOL isOption = (modifiers & NSEventModifierFlagOption) != 0;
BOOL isShift = (modifiers & NSEventModifierFlagShift) != 0;

if (!isCommand && !isControl && !isOption && !isShift) {
return nil;
}

NSMutableArray *parts = [NSMutableArray array];

if (isControl) [parts addObject:@"Win"];
if (isCommand) [parts addObject:@"Ctrl"];
if (isOption) [parts addObject:@"Alt"];
if (isShift) [parts addObject:@"Shift"];

// Get the character key
NSString *charString = nil;
NSString *specialKeyString = [[self _specialKeys] objectForKey:@(keystroke.keyCode)];
if (specialKeyString) {
// We might want to map some symbols to text if possible, but keeping them as is for now is safer
// unless we have a map for Windows names.
// For example, arrow keys are symbols in _specialKeys.
charString = specialKeyString;
} else {
charString = [self translatedCharacterForKeystroke:keystroke];
}

if (charString.length > 0) {
[parts addObject:[charString uppercaseString]];
}

return [parts componentsJoinedByString:@"+"];
}

- (NSString *)translatedCharacterForKeystroke:(KCKeystroke *)keystroke {
if ([self shouldReturnOriginalCharactersForKeyCode:keystroke.keyCode
characters:keystroke.characters] && keystroke.isCommand) {
Expand Down
25 changes: 19 additions & 6 deletions keycastr/Svelte.nib/designable.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified keycastr/Svelte.nib/keyedobjects.nib
Binary file not shown.
Loading