We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1213

Summary: Modifier key state incorrect when switching spaces on OS X
Product: SDL Reporter: Vern Jensen <vern>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P1 CC: icculus
Version: HG 2.0Keywords: target-2.0.0
Hardware: x86   
OS: Mac OS X 10.6   

Description Vern Jensen 2011-05-24 10:15:16 UTC
Process:

1) Set up "Spaces" on Mac OS X to use Command-arrow keys to switch spaces.
2) Run an SDL program.
3) Use Command-arrow to switch spaces to another space and back.
4) Resume using the SDL program.

At this point, checking:

if ( (event->key.keysym.mod & KMOD_GUI) ) 

for keyDown events will result in incorrect values -- the command key will incorrectly be reported by SDL events as being "down" even when it has been released. i.e. SDL doesn't detect, when losing focus, that the key was ever released.
Comment 1 Vern Jensen 2011-05-24 10:22:49 UTC
Additional note: if I push any modifier key upon returning to the SDL app, such as "control", I'll instantly get both a keyDown event for control AND a keyUp event for command, even though command was released long before. So something about pushing a different modifier key gets SDL to "recognize" that command is no longer held down.

Additionally, calling SDL_PumpEvents() in response to a SDL_WINDOWEVENT_FOCUS_GAINED event does not help. The user must push a modifier key to "fix" the problem.
Comment 2 Vern Jensen 2011-05-24 10:29:06 UTC
I discovered SDL_SetModState in the documentation. For now, manually calling:

SDL_SetModState(0);

upon a window focus gained event seems to solve the problem. I'm not sure what to pass other than 0, since I couldn't find SDL_Mod in the headers or docs wiki, but 0 seems to work just fine. For now, this will let me work around the bug.
Comment 3 Ryan C. Gordon 2013-07-12 18:52:52 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 1.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 4 Ryan C. Gordon 2013-07-18 22:49:29 UTC
Either we fixed this at some point, or Mac OS X 10.8 fixed it: the window loses focus when switching spaces with the hotkey, and the command key is reported in an SDL key-release event (and thus, the KMOD_GUI flag unsticks).

Marking this fixed.

--ryan.