mirror of
https://github.com/keycastr/keycastr.git
synced 2026-05-15 06:06:06 -06:00
Quick POC to enable displaying modified keys instead of keycaps
Only do this if it's not a command key (i.e. control or command modifier) Checkpoint before refactoring
This commit is contained in:
parent
7979161f57
commit
91165edcb0
2 changed files with 18 additions and 8 deletions
|
|
@ -161,11 +161,13 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4";
|
|||
- (id)transformedValue:(KCKeycastrEvent *)event
|
||||
{
|
||||
NSEventModifierFlags _modifiers = event.modifierFlags;
|
||||
BOOL isOption = (_modifiers & NSEventModifierFlagOption) != 0;
|
||||
BOOL isShifted = (_modifiers & NSEventModifierFlagShift) != 0;
|
||||
BOOL isOption = _modifiers & NSEventModifierFlagOption;
|
||||
BOOL isShifted = _modifiers & NSEventModifierFlagShift;
|
||||
|
||||
BOOL needsShiftGlyph = NO;
|
||||
|
||||
BOOL displayModifiedKeyWhenOptionPressed = YES;
|
||||
|
||||
NSMutableString *mutableResponse = [NSMutableString string];
|
||||
|
||||
if (_modifiers & NSEventModifierFlagControl)
|
||||
|
|
@ -173,17 +175,19 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4";
|
|||
[mutableResponse appendString:kControlKeyString];
|
||||
}
|
||||
|
||||
if (isOption)
|
||||
if (isOption && ([event isKindOfClass:[KCKeystroke class]] && [(KCKeystroke *)event isCommandKey]))
|
||||
{
|
||||
[mutableResponse appendString:kAltKeyString];
|
||||
}
|
||||
|
||||
if (isShifted)
|
||||
{
|
||||
if (_modifiers & (NSEventModifierFlagControl | NSEventModifierFlagOption | NSEventModifierFlagCommand))
|
||||
if (_modifiers & (NSEventModifierFlagControl | NSEventModifierFlagCommand))
|
||||
[mutableResponse appendString:kShiftKeyString];
|
||||
else
|
||||
needsShiftGlyph = YES;
|
||||
else if (isOption && !displayModifiedKeyWhenOptionPressed)
|
||||
[mutableResponse appendString:kShiftKeyString];
|
||||
else
|
||||
needsShiftGlyph = !displayModifiedKeyWhenOptionPressed;
|
||||
}
|
||||
|
||||
if (_modifiers & NSEventModifierFlagCommand)
|
||||
|
|
@ -230,7 +234,11 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4";
|
|||
return mutableResponse;
|
||||
}
|
||||
|
||||
[mutableResponse appendString:[self translatedCharacterForKeystroke:keystroke]];
|
||||
if (displayModifiedKeyWhenOptionPressed && !keystroke.isCommandKey) {
|
||||
[mutableResponse appendString:keystroke.characters];
|
||||
} else {
|
||||
[mutableResponse appendString:[self translatedCharacterForKeystroke:keystroke]];
|
||||
}
|
||||
|
||||
if (isCommandKey || isShifted)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) 2009 Stephen Deken
|
||||
// Copyright (c) 2020-2023 Andrew Kitchen
|
||||
// Copyright (c) 2020-2024 Andrew Kitchen
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
|
|
@ -33,6 +33,8 @@
|
|||
@interface KCKeystroke : KCKeycastrEvent
|
||||
|
||||
@property (nonatomic, readonly) uint16_t keyCode;
|
||||
@property (nonatomic, copy, readonly) NSString *characters;
|
||||
@property (nonatomic, copy, readonly) NSString *charactersIgnoringModifiers;
|
||||
|
||||
/// A Keystroke is a command key if it includes a Control or Command key; Option and Shift are only considered modifiers.
|
||||
- (BOOL)isCommandKey;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue