mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 12:02:00 +00:00
Simplified character input.
This commit is contained in:
parent
1027935cdf
commit
d6d5fb2684
@ -305,37 +305,6 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Translates a Windows key to Unicode
|
||||
//========================================================================
|
||||
|
||||
static void translateChar(_GLFWwindow* window, DWORD wParam, DWORD lParam)
|
||||
{
|
||||
BYTE keyboard_state[256];
|
||||
WCHAR unicode_buf[10];
|
||||
UINT scan_code;
|
||||
int i, num_chars;
|
||||
|
||||
GetKeyboardState(keyboard_state);
|
||||
|
||||
// Derive scan code from lParam and action
|
||||
scan_code = (lParam & 0x01ff0000) >> 16;
|
||||
|
||||
num_chars = ToUnicode(
|
||||
wParam, // virtual-key code
|
||||
scan_code, // scan code
|
||||
keyboard_state, // key-state array
|
||||
unicode_buf, // buffer for translated key
|
||||
10, // size of translated key buffer
|
||||
0 // active-menu flag
|
||||
);
|
||||
|
||||
// Report characters
|
||||
for (i = 0; i < num_chars; i++)
|
||||
_glfwInputChar(window, (int) unicode_buf[i]);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Window callback function (handles window events)
|
||||
//========================================================================
|
||||
@ -459,13 +428,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
||||
|
||||
if (_glfwLibrary.charCallback)
|
||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_CHAR:
|
||||
{
|
||||
_glfwInputChar(window, wParam);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
@ -1177,9 +1148,7 @@ void _glfwPlatformPollEvents(void)
|
||||
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
switch (msg.message)
|
||||
{
|
||||
case WM_QUIT:
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
// Treat WM_QUIT as a close on all windows
|
||||
|
||||
@ -1189,15 +1158,11 @@ void _glfwPlatformPollEvents(void)
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
window = window->next;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
else
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user