Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 01eddfa

Browse files
committed
Mask 0x100 bit instead of comparison
1 parent 7f4f62d commit 01eddfa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
4747
case NSEventTypeKeyUp:
4848
type = @"keyup";
4949
break;
50-
case NSEventTypeFlagsChanged:
51-
if (event.modifierFlags < _previouslyPressedFlags) {
50+
case NSEventTypeFlagsChanged: {
51+
// Remove the 0x100 bit set by Cocoa when no modifiers are pressed.
52+
NSEventModifierFlags modifierFlags = event.modifierFlags & ~0x100;
53+
if (modifierFlags < _previouslyPressedFlags) {
5254
type = @"keyup";
53-
} else if (event.modifierFlags > _previouslyPressedFlags &&
54-
event.modifierFlags > 0x100) { // 0x100 is empty modifierFlags
55+
} else if (modifierFlags > _previouslyPressedFlags) {
5556
type = @"keydown";
5657
} else {
5758
// ignore duplicate modifiers; This can happen in situations like switching
5859
// between application windows when MacOS only sends the up event to new window.
5960
return;
6061
}
6162
break;
63+
}
6264
default:
6365
NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
6466
}

0 commit comments

Comments
 (0)