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

Commit 388aaf7

Browse files
committed
Mask 0x100 bit instead of comparison
1 parent 7f4f62d commit 388aaf7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ - (nonnull instancetype)initWithChannel:(nonnull FlutterBasicMessageChannel*)cha
3939
}
4040

4141
- (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
42+
// Remove the 0x100 bit set by Cocoa when no modifiers are pressed.
43+
NSEventModifierFlags modifierFlags = event.modifierFlags & ~0x100;
4244
NSString* type;
4345
switch (event.type) {
4446
case NSEventTypeKeyDown:
@@ -48,10 +50,9 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
4850
type = @"keyup";
4951
break;
5052
case NSEventTypeFlagsChanged:
51-
if (event.modifierFlags < _previouslyPressedFlags) {
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
@@ -62,7 +63,7 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
6263
default:
6364
NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
6465
}
65-
_previouslyPressedFlags = event.modifierFlags;
66+
_previouslyPressedFlags = modifierFlags;
6667
NSMutableDictionary* keyMessage = [@{
6768
@"keymap" : @"macos",
6869
@"type" : type,

0 commit comments

Comments
 (0)