diff --git a/keycastr/KCEventTransformer.m b/keycastr/KCEventTransformer.m index 31f4534..d9f1ed9 100644 --- a/keycastr/KCEventTransformer.m +++ b/keycastr/KCEventTransformer.m @@ -219,8 +219,8 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4"; NSEventModifierFlags _modifiers = event.modifierFlags; BOOL hasOptionModifier = (_modifiers & NSEventModifierFlagOption) != 0; BOOL hasShiftModifier = (_modifiers & NSEventModifierFlagShift) != 0; - BOOL isCommand = (_modifiers & (NSEventModifierFlagControl | NSEventModifierFlagCommand)) != 0; - + BOOL isCommand = event.isCommand; + BOOL needsShiftGlyph = NO; NSMutableString *mutableResponse = [NSMutableString string]; @@ -237,10 +237,8 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4"; if (hasShiftModifier) { - if (isCommand) + if (isCommand || (hasOptionModifier && !_displayModifiedCharacters)) [mutableResponse appendString:kShiftKeyString]; - else if (hasOptionModifier && !_displayModifiedCharacters) - [mutableResponse appendString:kShiftKeyString]; else needsShiftGlyph = !_displayModifiedCharacters; } @@ -267,7 +265,7 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4"; KCKeystroke *keystroke = (KCKeystroke *)event; // check for bare shift-tab as left tab special case - if (hasShiftModifier && !keystroke.isCommand && !hasOptionModifier) + if (hasShiftModifier && !isCommand && !hasOptionModifier) { if (keystroke.keyCode == 48) { [mutableResponse appendString:kLeftTabString]; @@ -281,7 +279,7 @@ static NSString* kLeftTabString = @"\xe2\x87\xa4"; } void(^appendModifiers)(BOOL) = ^(BOOL append) { - if (append && !keystroke.isCommand) { + if (append && !isCommand) { if (hasOptionModifier) { [mutableResponse appendString:kOptionKeyString]; } diff --git a/keycastr/KCKeycastrEvent.h b/keycastr/KCKeycastrEvent.h index 2d0fd7d..931ce8c 100644 --- a/keycastr/KCKeycastrEvent.h +++ b/keycastr/KCKeycastrEvent.h @@ -32,6 +32,12 @@ @property (nonatomic, readonly) NSEventType type; @property (nonatomic, readonly) NSEventModifierFlags modifierFlags; +/// An event is a command if it includes the Control or Command key; Option and Shift are only considered modifiers. +@property (nonatomic, readonly) BOOL isCommand; + +/// Indicates whether a Keystroke has any of the Control, Command, Option or Shift modifiers applied. +@property (nonatomic, readonly) BOOL isModified; + + (instancetype)eventWithNSEvent:(NSEvent *)event; - (instancetype)initWithNSEvent:(NSEvent *)event NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; diff --git a/keycastr/KCKeycastrEvent.m b/keycastr/KCKeycastrEvent.m index 4694c92..82fc65a 100644 --- a/keycastr/KCKeycastrEvent.m +++ b/keycastr/KCKeycastrEvent.m @@ -52,6 +52,14 @@ return self; } +- (BOOL)isCommand { + return (self.modifierFlags & (NSEventModifierFlagControl | NSEventModifierFlagCommand)) != 0; +} + +- (BOOL)isModified { + return (self.modifierFlags & (NSEventModifierFlagControl | NSEventModifierFlagCommand | NSEventModifierFlagOption | NSEventModifierFlagShift)) != 0; +} + - (NSString *)convertToString { return [[KCEventTransformer currentTransformer] transformedValue:self]; } diff --git a/keycastr/KCKeystroke.h b/keycastr/KCKeystroke.h index b57666f..6060af6 100644 --- a/keycastr/KCKeystroke.h +++ b/keycastr/KCKeystroke.h @@ -36,10 +36,4 @@ @property (nonatomic, copy, readonly) NSString *characters; @property (nonatomic, copy, readonly) NSString *charactersIgnoringModifiers; -/// A Keystroke is a command if it includes the Control or Command key; Option and Shift are only considered modifiers. -- (BOOL)isCommand; - -/// Indicates whether a Keystroke has any of the Control, Command, Option or Shift modifiers applied. -- (BOOL)isModified; - @end diff --git a/keycastr/KCKeystroke.m b/keycastr/KCKeystroke.m index 98fda52..dc837ea 100644 --- a/keycastr/KCKeystroke.m +++ b/keycastr/KCKeystroke.m @@ -57,14 +57,6 @@ [super dealloc]; } -- (BOOL)isCommand { - return (self.modifierFlags & (NSEventModifierFlagControl | NSEventModifierFlagCommand)) != 0; -} - -- (BOOL)isModified { - return (self.modifierFlags & (NSEventModifierFlagControl | NSEventModifierFlagCommand | NSEventModifierFlagOption | NSEventModifierFlagShift)) != 0; -} - - (NSString *)description { return [NSString stringWithFormat:@"", self.keyCode, self.modifierFlags, _characters, _charactersIgnoringModifiers];