diff --git a/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm b/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm index b6aaae1376247..b8ba7ff043f9e 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm @@ -50,7 +50,8 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback { case NSEventTypeFlagsChanged: if (event.modifierFlags < _previouslyPressedFlags) { type = @"keyup"; - } else if (event.modifierFlags > _previouslyPressedFlags) { + } else if (event.modifierFlags > _previouslyPressedFlags && + event.modifierFlags > 0x100) { // 0x100 is empty modifierFlags type = @"keydown"; } else { // ignore duplicate modifiers; This can happen in situations like switching diff --git a/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm b/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm index 01254d6b7c780..9db070a52c289 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm @@ -52,9 +52,18 @@ callback(keyMessage); })); - // Key down FlutterChannelKeyResponder* responder = [[FlutterChannelKeyResponder alloc] initWithChannel:mockKeyEventChannel]; + + // Empty modifiers. Shouldn't result in any event + [responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, 60) + callback:^(BOOL handled) { + [responses addObject:@(handled)]; + }]; + + EXPECT_EQ([messages count], 0u); + + // Key down [responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", FALSE, 0) callback:^(BOOL handled) { [responses addObject:@(handled)];