src/video/winrt/SDL_winrtkeyboard.cpp
changeset 9188 480d583ce7ea
parent 8701 cb93e566a0c4
child 9189 5dc3c7c2864c
     1.1 --- a/src/video/winrt/SDL_winrtkeyboard.cpp	Fri Oct 24 19:50:29 2014 +0200
     1.2 +++ b/src/video/winrt/SDL_winrtkeyboard.cpp	Fri Oct 24 21:25:21 2014 -0400
     1.3 @@ -22,10 +22,6 @@
     1.4  
     1.5  #if SDL_VIDEO_DRIVER_WINRT
     1.6  
     1.7 -/* Standard C++11 includes */
     1.8 -#include <unordered_map>
     1.9 -
    1.10 -
    1.11  /* Windows-specific includes */
    1.12  #include <Windows.h>
    1.13  #include <agile.h>
    1.14 @@ -217,45 +213,47 @@
    1.15      SDL_SCANCODE_AC_HOME // VirtualKey.GoHome -- 172 : The go home key.
    1.16  };
    1.17  
    1.18 -static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
    1.19 +/* Attempt to translate a keycode that isn't listed in WinRT's VirtualKey enum.
    1.20 + */
    1.21 +static SDL_Scancode
    1.22 +WINRT_TranslateUnofficialKeycode(int keycode)
    1.23 +{
    1.24 +    switch (keycode) {
    1.25 +        case 173: return SDL_SCANCODE_MUTE;
    1.26 +        case 174: return SDL_SCANCODE_VOLUMEDOWN;
    1.27 +        case 175: return SDL_SCANCODE_VOLUMEUP;
    1.28 +        case 176: return SDL_SCANCODE_AUDIONEXT;
    1.29 +        case 177: return SDL_SCANCODE_AUDIOPREV;
    1.30 +        // case 178: return ;
    1.31 +        case 179: return SDL_SCANCODE_AUDIOPLAY;
    1.32 +        case 180: return SDL_SCANCODE_MAIL;
    1.33 +        case 181: return SDL_SCANCODE_MEDIASELECT;
    1.34 +        // case 182: return ;
    1.35 +        case 183: return SDL_SCANCODE_CALCULATOR;
    1.36 +        // case 184: return ;
    1.37 +        // case 185: return ;
    1.38 +        case 186: return SDL_SCANCODE_SEMICOLON;
    1.39 +        case 187: return SDL_SCANCODE_EQUALS;
    1.40 +        case 188: return SDL_SCANCODE_COMMA;
    1.41 +        case 189: return SDL_SCANCODE_MINUS;
    1.42 +        case 190: return SDL_SCANCODE_PERIOD;
    1.43 +        case 191: return SDL_SCANCODE_SLASH;
    1.44 +        case 192: return SDL_SCANCODE_GRAVE;
    1.45 +        // ?
    1.46 +        // ...
    1.47 +        // ?
    1.48 +        case 219: return SDL_SCANCODE_LEFTBRACKET;
    1.49 +        case 220: return SDL_SCANCODE_BACKSLASH;
    1.50 +        case 221: return SDL_SCANCODE_RIGHTBRACKET;
    1.51 +        case 222: return SDL_SCANCODE_APOSTROPHE;
    1.52 +        default: break;
    1.53 +    }
    1.54 +    return SDL_SCANCODE_UNKNOWN;
    1.55 +}
    1.56  
    1.57  static SDL_Scancode
    1.58  TranslateKeycode(int keycode)
    1.59  {
    1.60 -    if (WinRT_Unofficial_Keycodes.empty()) {
    1.61 -        /* Set up a table of keycodes that aren't listed in WinRT's
    1.62 -         * VirtualKey enum.
    1.63 -         */
    1.64 -
    1.65 -        WinRT_Unofficial_Keycodes[173] = SDL_SCANCODE_MUTE;
    1.66 -        WinRT_Unofficial_Keycodes[174] = SDL_SCANCODE_VOLUMEDOWN;
    1.67 -        WinRT_Unofficial_Keycodes[175] = SDL_SCANCODE_VOLUMEUP;
    1.68 -        WinRT_Unofficial_Keycodes[176] = SDL_SCANCODE_AUDIONEXT;
    1.69 -        WinRT_Unofficial_Keycodes[177] = SDL_SCANCODE_AUDIOPREV;
    1.70 -        // WinRT_Unofficial_Keycodes[178] = ;
    1.71 -        WinRT_Unofficial_Keycodes[179] = SDL_SCANCODE_AUDIOPLAY;
    1.72 -        WinRT_Unofficial_Keycodes[180] = SDL_SCANCODE_MAIL;
    1.73 -        WinRT_Unofficial_Keycodes[181] = SDL_SCANCODE_MEDIASELECT;
    1.74 -        // WinRT_Unofficial_Keycodes[182] = ;
    1.75 -        WinRT_Unofficial_Keycodes[183] = SDL_SCANCODE_CALCULATOR;
    1.76 -        // WinRT_Unofficial_Keycodes[184] = ;
    1.77 -        // WinRT_Unofficial_Keycodes[185] = ;
    1.78 -        WinRT_Unofficial_Keycodes[186] = SDL_SCANCODE_SEMICOLON;
    1.79 -        WinRT_Unofficial_Keycodes[187] = SDL_SCANCODE_EQUALS;
    1.80 -        WinRT_Unofficial_Keycodes[188] = SDL_SCANCODE_COMMA;
    1.81 -        WinRT_Unofficial_Keycodes[189] = SDL_SCANCODE_MINUS;
    1.82 -        WinRT_Unofficial_Keycodes[190] = SDL_SCANCODE_PERIOD;
    1.83 -        WinRT_Unofficial_Keycodes[191] = SDL_SCANCODE_SLASH;
    1.84 -        WinRT_Unofficial_Keycodes[192] = SDL_SCANCODE_GRAVE;
    1.85 -        // ?
    1.86 -        // ...
    1.87 -        // ?
    1.88 -        WinRT_Unofficial_Keycodes[219] = SDL_SCANCODE_LEFTBRACKET;
    1.89 -        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_BACKSLASH;
    1.90 -        WinRT_Unofficial_Keycodes[221] = SDL_SCANCODE_RIGHTBRACKET;
    1.91 -        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_APOSTROPHE;
    1.92 -    }
    1.93 -
    1.94      /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
    1.95         http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
    1.96         If that fails, fall back to a Win32 virtual key.
    1.97 @@ -267,9 +265,7 @@
    1.98          scancode = WinRT_Official_Keycodes[keycode];
    1.99      }
   1.100      if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.101 -        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
   1.102 -            scancode = WinRT_Unofficial_Keycodes[keycode];
   1.103 -        }
   1.104 +        scancode = WINRT_TranslateUnofficialKeycode(keycode);
   1.105      }
   1.106      if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.107          SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);