prefer virtual keycodes over scancodes for extended keys

This commit is contained in:
ouned 2017-06-03 09:13:08 +02:00
parent 195b8bd8ee
commit 34769abd46
1 changed files with 78 additions and 66 deletions

View File

@ -82,15 +82,9 @@
#endif #endif
static SDL_Scancode static SDL_Scancode
WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam) VKeytoScancode(WPARAM vkey)
{ {
SDL_Scancode code; switch (vkey) {
char bIsExtended;
int nScanCode = (lParam >> 16) & 0xFF;
/* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
if (nScanCode == 0 || nScanCode == 0x45) {
switch(wParam) {
case VK_CLEAR: return SDL_SCANCODE_CLEAR; case VK_CLEAR: return SDL_SCANCODE_CLEAR;
case VK_MODECHANGE: return SDL_SCANCODE_MODE; case VK_MODECHANGE: return SDL_SCANCODE_MODE;
case VK_SELECT: return SDL_SCANCODE_SELECT; case VK_SELECT: return SDL_SCANCODE_SELECT;
@ -145,6 +139,18 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
} }
} }
static SDL_Scancode
WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
{
SDL_Scancode code;
char bIsExtended;
int nScanCode = (lParam >> 16) & 0xFF;
/* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
if (nScanCode == 0 || nScanCode == 0x45) {
return VKeytoScancode(wParam);
}
if (nScanCode > 127) if (nScanCode > 127)
return SDL_SCANCODE_UNKNOWN; return SDL_SCANCODE_UNKNOWN;
@ -178,6 +184,11 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
default: default:
break; break;
} }
/* prefer virtual keycodes over scancodes for extended keys */
} else {
SDL_Scancode vc = VKeytoScancode(wParam);
if (vc != SDL_SCANCODE_UNKNOWN) {
code = vc;
} else { } else {
switch (code) { switch (code) {
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
@ -194,6 +205,7 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
break; break;
} }
} }
}
return code; return code;
} }