From acd09b270b2eaa6a7faff4c5a12d4086e7dbca4c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 1 Aug 2013 01:50:02 -0400 Subject: [PATCH] Windows: Unstick shift keys in a timely manner when the OS loses a KEYUP event. Fixes Bugzilla #1959. --- src/video/windows/SDL_windowsevents.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 78d31d54e..3e79d69cd 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -766,11 +766,24 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) void WIN_PumpEvents(_THIS) { + const Uint8 *keystate; MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } + + /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one. + You won't get a KEYUP until both are released, and that keyup will only be for the second + key you released. Take heroic measures and check the keystate as of the last handled event, + and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */ + keystate = SDL_GetKeyboardState(NULL); + if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) { + SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); + } + if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) { + SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT); + } } static int app_registered = 0;