From 3d2540c373c53a8ddfba806fb83cdb9e39a61467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 13 Sep 2019 01:16:13 +0200 Subject: [PATCH] Win32: Cleanup keyboard input flag parsing This replaces some magic numbers with the corresponding winuser.h provided macros and unifies how the MSB from Get*KeyState is tested. --- src/win32_window.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index fbb05b6a..efb4e043 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -481,7 +481,7 @@ static int translateKey(WPARAM wParam, LPARAM lParam) DWORD time; // Right side keys have the extended key bit set - if (lParam & 0x01000000) + if (HIWORD(lParam) & KF_EXTENDED) return GLFW_KEY_RIGHT_CONTROL; // HACK: Alt Gr sends Left Ctrl and then Right Alt in close sequence @@ -497,7 +497,7 @@ static int translateKey(WPARAM wParam, LPARAM lParam) next.message == WM_SYSKEYUP) { if (next.wParam == VK_MENU && - (next.lParam & 0x01000000) && + (HIWORD(next.lParam) & KF_EXTENDED) && next.time == time) { // Next message is Right Alt down so discard this @@ -740,8 +740,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_SYSKEYUP: { const int key = translateKey(wParam, lParam); - const int scancode = (lParam >> 16) & 0x1ff; - const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS; + const int scancode = (HIWORD(lParam) & 0x1ff); + const int action = (HIWORD(lParam) & KF_UP) ? GLFW_RELEASE : GLFW_PRESS; const int mods = getKeyMods(); if (key == _GLFW_KEY_INVALID) @@ -1934,8 +1934,8 @@ void _glfwPlatformPollEvents(void) window = GetPropW(handle, L"GLFW"); if (window) { - const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; - const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; + const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) & 0x8000) != 0; + const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) & 0x8000) != 0; if (!lshift && window->keys[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS) {