Skip to content

Commit

Permalink
Mask 0x100 bit instead of comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed Jul 30, 2021
1 parent 7f4f62d commit 388aaf7
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ - (nonnull instancetype)initWithChannel:(nonnull FlutterBasicMessageChannel*)cha
}

- (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
// Remove the 0x100 bit set by Cocoa when no modifiers are pressed.
NSEventModifierFlags modifierFlags = event.modifierFlags & ~0x100;
NSString* type;
switch (event.type) {
case NSEventTypeKeyDown:
Expand All @@ -48,10 +50,9 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
type = @"keyup";
break;
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
if (modifierFlags < _previouslyPressedFlags) {
type = @"keyup";
} else if (event.modifierFlags > _previouslyPressedFlags &&
event.modifierFlags > 0x100) { // 0x100 is empty modifierFlags
} else if (modifierFlags > _previouslyPressedFlags) {
type = @"keydown";
} else {
// ignore duplicate modifiers; This can happen in situations like switching
Expand All @@ -62,7 +63,7 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
default:
NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
}
_previouslyPressedFlags = event.modifierFlags;
_previouslyPressedFlags = modifierFlags;
NSMutableDictionary* keyMessage = [@{
@"keymap" : @"macos",
@"type" : type,
Expand Down

0 comments on commit 388aaf7

Please sign in to comment.