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 4532

Summary: SDL_GetKeyState() Reports key as pressed when window gets hidden
Product: SDL Reporter: simon.gassner
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.9   
Hardware: x86_64   
OS: Windows 7   
Attachments: Example to reproduce the issue

Description simon.gassner 2019-03-02 12:33:36 UTC
Created attachment 3686 [details]
Example to reproduce the issue

When a key is pressed while the window gets hidden, SDL_GetKeyState() will keep the state as activated/pressed. Even when the window is shown again, the key still returns as pressed, as long as until it’s really pressed again.
Also, the window itself seems to stay focused on the keyboard (when hidden), at least SDL_GetKeyboardFocus() says so. According to the Win32 API, if a window gets hidden, another window should be activated (https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-showwindow SW_HIDE parameter), and I think this should apply to SDL aswell?

Expected behaviour:
- If the window gets hidden, SDL_GetKeyState() should not return any activated keys.
- The window should loose focus and therefore, SDL_GetKeyboardFocus() should not return the same window.

Workarounds:

I found a workaround, if SDL_MinimizeWindow() followed by SDL_RestoreWindow() are called before hidding the window via SDL_HideWindow(), the keystate is working correctly. However, the window still stays active.

How to reproduce:

For me, it reproduces every time, I wrote a sample to isolate/test it (See attachment), Keys WASD are defined for testing, W will hide the window (It will be shown again automatically after 3 seconds).