mirror of
https://github.com/glfw/glfw.git
synced 2024-11-29 21:37:27 +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)
|
// Window callback function (handles window events)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -459,13 +428,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
{
|
{
|
||||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
||||||
|
|
||||||
if (_glfwLibrary.charCallback)
|
|
||||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WM_CHAR:
|
||||||
|
{
|
||||||
|
_glfwInputChar(window, wParam);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
case WM_SYSKEYUP:
|
case WM_SYSKEYUP:
|
||||||
{
|
{
|
||||||
@ -1177,9 +1148,7 @@ void _glfwPlatformPollEvents(void)
|
|||||||
|
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
switch (msg.message)
|
if (msg.message == WM_QUIT)
|
||||||
{
|
|
||||||
case WM_QUIT:
|
|
||||||
{
|
{
|
||||||
// Treat WM_QUIT as a close on all windows
|
// Treat WM_QUIT as a close on all windows
|
||||||
|
|
||||||
@ -1189,15 +1158,11 @@ void _glfwPlatformPollEvents(void)
|
|||||||
_glfwInputWindowCloseRequest(window);
|
_glfwInputWindowCloseRequest(window);
|
||||||
window = window->next;
|
window = window->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
default:
|
|
||||||
{
|
{
|
||||||
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user