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 - SDL_GetKeyState() Reports key as pressed when window gets hidden
Summary: SDL_GetKeyState() Reports key as pressed when window gets hidden
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.9
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-02 12:33 UTC by simon.gassner
Modified: 2019-03-02 12:33 UTC (History)
0 users

See Also:


Attachments
Example to reproduce the issue (1.72 KB, text/plain)
2019-03-02 12:33 UTC, simon.gassner
Details

Note You need to log in before you can comment on or make changes to this bug.
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).