1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Simplified character input.

This commit is contained in:
Camilla Berglund 2012-09-19 13:17:53 +02:00
parent 1027935cdf
commit d6d5fb2684

View File

@ -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,28 +1148,22 @@ 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
window = _glfwLibrary.windowListHead;
while (window)
{ {
// Treat WM_QUIT as a close on all windows _glfwInputWindowCloseRequest(window);
window = window->next;
window = _glfwLibrary.windowListHead;
while (window)
{
_glfwInputWindowCloseRequest(window);
window = window->next;
}
break;
}
default:
{
DispatchMessage(&msg);
break;
} }
} }
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} }
// LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix) // LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)