Fixed bug 4709 - incorrect (not) handling of windows on-screen cursor keys
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Feb 2020 08:36:13 -0800
changeset 135043d991f099f58
parent 13503 eb6023298d0e
child 13505 0c62973859eb
Fixed bug 4709 - incorrect (not) handling of windows on-screen cursor keys

Alex Denisov

When using Win10 on-screen keyboard (tooltip.exe), the left and right cursor keys in it do not produce SDLK_LEFT and SDLK_RIGHT events.

Windows messages generated by the on-screen keyboard, for some reason, have their scancodes set to zeroes. Here is the log from Spy++:

WM_KEYDOWN nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
WM_KEYUP nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Regular physical keyboard produces VK_LEFT (ScanCode:4B) and VK_RIGHT (ScanCode:4D) which are interpreted correctly.

With on-screen keyboard, the switch statement in VKeytoScancode() does not check for VK_LEFT and VK_RIGHT, returning SDL_SCANCODE_UNKNOWN, which in turn does not get mapped to anything (because the scan codes are zeroes).
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Tue Feb 11 08:26:46 2020 -0800
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Tue Feb 11 08:36:13 2020 -0800
     1.3 @@ -86,6 +86,11 @@
     1.4  /* Windows generates this virtual keycode for Keypad 5 when NumLock is off.
     1.5      case VK_CLEAR: return SDL_SCANCODE_CLEAR;
     1.6  */
     1.7 +    case VK_LEFT: return SDL_SCANCODE_LEFT;
     1.8 +    case VK_UP: return SDL_SCANCODE_UP;
     1.9 +    case VK_RIGHT: return SDL_SCANCODE_RIGHT;
    1.10 +    case VK_DOWN: return SDL_SCANCODE_DOWN;
    1.11 +
    1.12      case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    1.13      case VK_SELECT: return SDL_SCANCODE_SELECT;
    1.14      case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;