From 61cd57d378e6bf5a62a8bf49e02164df63924c56 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 29 Nov 2023 21:38:41 -0500 Subject: [PATCH] cocoa: Resync modifier keypressed on NSEventTypeFlagsChanged event. Fixes #7507. (cherry picked from commit 70b65d4170bbff6a8c2ffc9b5834ec85384f6fc0) --- src/video/cocoa/SDL_cocoakeyboard.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index c81880d32..ca91d4495 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -437,9 +437,19 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event) case NSEventTypeKeyUp: SDL_SendKeyboardKey(SDL_RELEASED, code); break; - case NSEventTypeFlagsChanged: - HandleModifiers(_this, code, (unsigned int)[event modifierFlags]); + case NSEventTypeFlagsChanged: { + // see if the new modifierFlags mean any existing keys should be pressed/released... + const unsigned int modflags = (unsigned int)[event modifierFlags]; + HandleModifiers(_this, SDL_SCANCODE_LSHIFT, modflags); + HandleModifiers(_this, SDL_SCANCODE_LCTRL, modflags); + HandleModifiers(_this, SDL_SCANCODE_LALT, modflags); + HandleModifiers(_this, SDL_SCANCODE_LGUI, modflags); + HandleModifiers(_this, SDL_SCANCODE_RSHIFT, modflags); + HandleModifiers(_this, SDL_SCANCODE_RCTRL, modflags); + HandleModifiers(_this, SDL_SCANCODE_RALT, modflags); + HandleModifiers(_this, SDL_SCANCODE_RGUI, modflags); break; + } default: /* just to avoid compiler warnings */ break; }