From 43c191045337fa4c53cc28e496f81ff891f3720f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 29 Jan 2017 18:47:59 +0100 Subject: [PATCH] Win32: Cleanup --- src/win32_window.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index ab6c4a10..5c357102 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1413,28 +1413,24 @@ void _glfwPlatformPollEvents(void) handle = GetActiveWindow(); if (handle) { - // LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix) - // This is the only async event handling in GLFW, but it solves some - // nasty problems + // NOTE: Shift keys on Windows tend to "stick" when both are pressed as + // no key up message is generated by the first key release + // HACK: Query actual key state and synthesize release events as needed window = GetPropW(handle, L"GLFW"); if (window) { - const int mods = getAsyncKeyMods(); + const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; + const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; - // Get current state of left and right shift keys - const int lshiftDown = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; - const int rshiftDown = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; - - // See if this differs from our belief of what has happened - // (we only have to check for lost key up events) - if (!lshiftDown && window->keys[GLFW_KEY_LEFT_SHIFT] == 1) + if (!lshift && window->keys[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS) { + const int mods = getAsyncKeyMods(); const int scancode = _glfw.win32.scancodes[GLFW_KEY_LEFT_SHIFT]; _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods); } - - if (!rshiftDown && window->keys[GLFW_KEY_RIGHT_SHIFT] == 1) + else if (!rshift && window->keys[GLFW_KEY_RIGHT_SHIFT] == GLFW_PRESS) { + const int mods = getAsyncKeyMods(); const int scancode = _glfw.win32.scancodes[GLFW_KEY_RIGHT_SHIFT]; _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods); }