From d3b323f89d48c305a1f38f26e5e49673324c9afd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 27 Dec 2015 23:39:43 -0500 Subject: [PATCH] Mac: Fix keyboard state if capslock was toggled while app wasn't in foreground. --- src/video/cocoa/SDL_cocoawindow.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index c815db540..3ed407853 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -588,6 +588,17 @@ SetWindowStyle(SDL_Window * window, unsigned int style) if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) { [NSMenu setMenuBarVisible:NO]; } + + /* On pre-10.6, you might have the capslock key state wrong now. */ + if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6) { + const unsigned int oldflags = _data->videodata->modifierFlags & NSAlphaShiftKeyMask; + const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask; + if (oldflags != newflags) { + _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags; + SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); + SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); + } + } } - (void)windowDidResignKey:(NSNotification *)aNotification