WinRT: keyboard VirtualKey translation improvements from Sylvain Becker
authorDavid Ludwig <dludwig@pobox.com>
Thu, 17 Apr 2014 12:43:51 -0400
changeset 8701cb93e566a0c4
parent 8700 446c4e870681
child 8702 274017846e73
WinRT: keyboard VirtualKey translation improvements from Sylvain Becker

Changes included:
- adding support for a few, additional, VirtualKey constants
- removing accesses to 'windows_scancode_table', as the table's contents
don't line up with WinRT virtual keys. Using Windows older VK_* constants
may, however, be a good alternative in a future update.
src/video/winrt/SDL_winrtkeyboard.cpp
     1.1 --- a/src/video/winrt/SDL_winrtkeyboard.cpp	Thu Apr 17 12:44:08 2014 -0300
     1.2 +++ b/src/video/winrt/SDL_winrtkeyboard.cpp	Thu Apr 17 12:43:51 2014 -0400
     1.3 @@ -208,6 +208,13 @@
     1.4      SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
     1.5      SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
     1.6      SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
     1.7 +    SDL_SCANCODE_AC_BACK, // VirtualKey.GoBack -- 166 : The go back key.
     1.8 +    SDL_SCANCODE_AC_FORWARD, // VirtualKey.GoForward -- 167 : The go forward key.
     1.9 +    SDL_SCANCODE_AC_REFRESH, // VirtualKey.Refresh -- 168 : The refresh key.
    1.10 +    SDL_SCANCODE_AC_STOP, // VirtualKey.Stop -- 169 : The stop key.
    1.11 +    SDL_SCANCODE_AC_SEARCH, // VirtualKey.Search -- 170 : The search key.
    1.12 +    SDL_SCANCODE_AC_BOOKMARKS, // VirtualKey.Favorites -- 171 : The favorites key.
    1.13 +    SDL_SCANCODE_AC_HOME // VirtualKey.GoHome -- 172 : The go home key.
    1.14  };
    1.15  
    1.16  static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
    1.17 @@ -216,11 +223,37 @@
    1.18  TranslateKeycode(int keycode)
    1.19  {
    1.20      if (WinRT_Unofficial_Keycodes.empty()) {
    1.21 -        /* Set up a table of undocumented (by Microsoft), WinRT-specific,
    1.22 -           key codes: */
    1.23 -        // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
    1.24 -        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
    1.25 -        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
    1.26 +        /* Set up a table of keycodes that aren't listed in WinRT's
    1.27 +         * VirtualKey enum.
    1.28 +         */
    1.29 +
    1.30 +        WinRT_Unofficial_Keycodes[173] = SDL_SCANCODE_MUTE;
    1.31 +        WinRT_Unofficial_Keycodes[174] = SDL_SCANCODE_VOLUMEDOWN;
    1.32 +        WinRT_Unofficial_Keycodes[175] = SDL_SCANCODE_VOLUMEUP;
    1.33 +        WinRT_Unofficial_Keycodes[176] = SDL_SCANCODE_AUDIONEXT;
    1.34 +        WinRT_Unofficial_Keycodes[177] = SDL_SCANCODE_AUDIOPREV;
    1.35 +        // WinRT_Unofficial_Keycodes[178] = ;
    1.36 +        WinRT_Unofficial_Keycodes[179] = SDL_SCANCODE_AUDIOPLAY;
    1.37 +        WinRT_Unofficial_Keycodes[180] = SDL_SCANCODE_MAIL;
    1.38 +        WinRT_Unofficial_Keycodes[181] = SDL_SCANCODE_MEDIASELECT;
    1.39 +        // WinRT_Unofficial_Keycodes[182] = ;
    1.40 +        WinRT_Unofficial_Keycodes[183] = SDL_SCANCODE_CALCULATOR;
    1.41 +        // WinRT_Unofficial_Keycodes[184] = ;
    1.42 +        // WinRT_Unofficial_Keycodes[185] = ;
    1.43 +        WinRT_Unofficial_Keycodes[186] = SDL_SCANCODE_SEMICOLON;
    1.44 +        WinRT_Unofficial_Keycodes[187] = SDL_SCANCODE_EQUALS;
    1.45 +        WinRT_Unofficial_Keycodes[188] = SDL_SCANCODE_COMMA;
    1.46 +        WinRT_Unofficial_Keycodes[189] = SDL_SCANCODE_MINUS;
    1.47 +        WinRT_Unofficial_Keycodes[190] = SDL_SCANCODE_PERIOD;
    1.48 +        WinRT_Unofficial_Keycodes[191] = SDL_SCANCODE_SLASH;
    1.49 +        WinRT_Unofficial_Keycodes[192] = SDL_SCANCODE_GRAVE;
    1.50 +        // ?
    1.51 +        // ...
    1.52 +        // ?
    1.53 +        WinRT_Unofficial_Keycodes[219] = SDL_SCANCODE_LEFTBRACKET;
    1.54 +        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_BACKSLASH;
    1.55 +        WinRT_Unofficial_Keycodes[221] = SDL_SCANCODE_RIGHTBRACKET;
    1.56 +        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_APOSTROPHE;
    1.57      }
    1.58  
    1.59      /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
    1.60 @@ -239,11 +272,6 @@
    1.61          }
    1.62      }
    1.63      if (scancode == SDL_SCANCODE_UNKNOWN) {
    1.64 -        if (keycode < SDL_arraysize(windows_scancode_table)) {
    1.65 -            scancode = windows_scancode_table[keycode];
    1.66 -        }
    1.67 -    }
    1.68 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
    1.69          SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
    1.70      }
    1.71      return scancode;