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 01eddfa
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
case NSEventTypeKeyUp:
type = @"keyup";
break;
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
case NSEventTypeFlagsChanged: {
// Remove the 0x100 bit set by Cocoa when no modifiers are pressed.
NSEventModifierFlags modifierFlags = event.modifierFlags & ~0x100;
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
// between application windows when MacOS only sends the up event to new window.
return;
}
break;
}
default:
NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
}
Expand Down

0 comments on commit 01eddfa

Please sign in to comment.