mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Added scancode to key callback.
This commit is contained in:
+22
-11
@@ -34,6 +34,8 @@
|
||||
#include <malloc.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#define _GLFW_KEY_INVALID -2
|
||||
|
||||
|
||||
// Updates the cursor clip rect
|
||||
//
|
||||
@@ -214,7 +216,7 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// Next message is a RALT down message, which
|
||||
// means that this is not a proper LCTRL message
|
||||
return -1;
|
||||
return _GLFW_KEY_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,8 +362,8 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
default: break;
|
||||
}
|
||||
|
||||
// No matching translation was found, so return -1
|
||||
return -1;
|
||||
// No matching translation was found
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
// Window callback function (handles window events)
|
||||
@@ -471,7 +473,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS, getKeyMods());
|
||||
const int scancode = (lParam >> 16) & 0xff;
|
||||
const int key = translateKey(wParam, lParam);
|
||||
if (key == _GLFW_KEY_INVALID)
|
||||
break;
|
||||
|
||||
_glfwInputKey(window, key, scancode, GLFW_PRESS, getKeyMods());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -500,22 +507,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
const int mods = getKeyMods();
|
||||
const int scancode = (lParam >> 16) & 0xff;
|
||||
const int key = translateKey(wParam, lParam);
|
||||
if (key == _GLFW_KEY_INVALID)
|
||||
break;
|
||||
|
||||
if (wParam == VK_SHIFT)
|
||||
{
|
||||
// Release both Shift keys on Shift up event, as only one event
|
||||
// is sent even if both keys are released
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods);
|
||||
}
|
||||
else if (wParam == VK_SNAPSHOT)
|
||||
{
|
||||
// Key down is not reported for the print screen key
|
||||
_glfwInputKey(window, GLFW_KEY_PRINT_SCREEN, GLFW_PRESS, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_PRINT_SCREEN, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
|
||||
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
||||
}
|
||||
else
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE, getKeyMods());
|
||||
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1064,10 +1075,10 @@ void _glfwPlatformPollEvents(void)
|
||||
// See if this differs from our belief of what has happened
|
||||
// (we only have to check for lost key up events)
|
||||
if (!lshiftDown && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, 0, GLFW_RELEASE, mods);
|
||||
|
||||
if (!rshiftDown && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE, mods);
|
||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, 0, GLFW_RELEASE, mods);
|
||||
}
|
||||
|
||||
// Did the cursor move in an focused window that has captured the cursor
|
||||
|
||||
Reference in New Issue
Block a user