src/video/winrt/SDL_winrtkeyboard.cpp
author David Ludwig
Thu, 17 Apr 2014 12:43:51 -0400
changeset 8701 cb93e566a0c4
parent 8615 097646deaef2
child 9188 480d583ce7ea
permissions -rw-r--r--
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.
slouken@8582
     1
/*
slouken@8582
     2
  Simple DirectMedia Layer
slouken@8615
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@8582
     4
slouken@8582
     5
  This software is provided 'as-is', without any express or implied
slouken@8582
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@8582
     7
  arising from the use of this software.
slouken@8582
     8
slouken@8582
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@8582
    10
  including commercial applications, and to alter it and redistribute it
slouken@8582
    11
  freely, subject to the following restrictions:
slouken@8582
    12
slouken@8582
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@8582
    14
     claim that you wrote the original software. If you use this software
slouken@8582
    15
     in a product, an acknowledgment in the product documentation would be
slouken@8582
    16
     appreciated but is not required.
slouken@8582
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@8582
    18
     misrepresented as being the original software.
slouken@8582
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@8582
    20
*/
dludwig@8600
    21
#include "../../SDL_internal.h"
slouken@8582
    22
slouken@8582
    23
#if SDL_VIDEO_DRIVER_WINRT
slouken@8582
    24
slouken@8582
    25
/* Standard C++11 includes */
slouken@8582
    26
#include <unordered_map>
slouken@8582
    27
slouken@8582
    28
slouken@8582
    29
/* Windows-specific includes */
slouken@8582
    30
#include <Windows.h>
slouken@8582
    31
#include <agile.h>
slouken@8582
    32
slouken@8582
    33
slouken@8582
    34
/* SDL-specific includes */
slouken@8582
    35
#include <SDL.h>
slouken@8582
    36
#include "SDL_winrtevents_c.h"
slouken@8582
    37
slouken@8582
    38
extern "C" {
slouken@8582
    39
#include "../../events/scancodes_windows.h"
slouken@8582
    40
#include "../../events/SDL_keyboard_c.h"
slouken@8582
    41
}
slouken@8582
    42
slouken@8582
    43
slouken@8582
    44
static SDL_Scancode WinRT_Official_Keycodes[] = {
slouken@8582
    45
    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
slouken@8582
    46
    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
slouken@8582
    47
    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
slouken@8582
    48
    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
slouken@8582
    49
    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
slouken@8582
    50
    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
slouken@8582
    51
    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
slouken@8582
    52
    SDL_SCANCODE_UNKNOWN, // -- 7
slouken@8582
    53
    SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
slouken@8582
    54
    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
slouken@8582
    55
    SDL_SCANCODE_UNKNOWN, // -- 10
slouken@8582
    56
    SDL_SCANCODE_UNKNOWN, // -- 11
slouken@8582
    57
    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
slouken@8582
    58
    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
slouken@8582
    59
    SDL_SCANCODE_UNKNOWN, // -- 14
slouken@8582
    60
    SDL_SCANCODE_UNKNOWN, // -- 15
slouken@8582
    61
    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
slouken@8582
    62
    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
slouken@8582
    63
    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
slouken@8582
    64
    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
slouken@8582
    65
    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
slouken@8582
    66
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
slouken@8582
    67
    SDL_SCANCODE_UNKNOWN, // -- 22
slouken@8582
    68
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
slouken@8582
    69
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
slouken@8582
    70
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
slouken@8582
    71
    SDL_SCANCODE_UNKNOWN, // -- 26
slouken@8582
    72
    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
slouken@8582
    73
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
slouken@8582
    74
    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
slouken@8582
    75
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
slouken@8582
    76
    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
slouken@8582
    77
    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
slouken@8582
    78
    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
slouken@8582
    79
    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
slouken@8582
    80
    SDL_SCANCODE_END, // VirtualKey.End -- 35
slouken@8582
    81
    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
slouken@8582
    82
    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
slouken@8582
    83
    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
slouken@8582
    84
    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
slouken@8582
    85
    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
slouken@8582
    86
    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
slouken@8582
    87
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
slouken@8582
    88
    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
slouken@8582
    89
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
slouken@8582
    90
    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
slouken@8582
    91
    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
slouken@8582
    92
    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
slouken@8582
    93
    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
slouken@8582
    94
    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
slouken@8582
    95
    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
slouken@8582
    96
    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
slouken@8582
    97
    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
slouken@8582
    98
    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
slouken@8582
    99
    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
slouken@8582
   100
    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
slouken@8582
   101
    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
slouken@8582
   102
    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
slouken@8582
   103
    SDL_SCANCODE_UNKNOWN, // -- 58
slouken@8582
   104
    SDL_SCANCODE_UNKNOWN, // -- 59
slouken@8582
   105
    SDL_SCANCODE_UNKNOWN, // -- 60
slouken@8582
   106
    SDL_SCANCODE_UNKNOWN, // -- 61
slouken@8582
   107
    SDL_SCANCODE_UNKNOWN, // -- 62
slouken@8582
   108
    SDL_SCANCODE_UNKNOWN, // -- 63
slouken@8582
   109
    SDL_SCANCODE_UNKNOWN, // -- 64
slouken@8582
   110
    SDL_SCANCODE_A, // VirtualKey.A -- 65
slouken@8582
   111
    SDL_SCANCODE_B, // VirtualKey.B -- 66
slouken@8582
   112
    SDL_SCANCODE_C, // VirtualKey.C -- 67
slouken@8582
   113
    SDL_SCANCODE_D, // VirtualKey.D -- 68
slouken@8582
   114
    SDL_SCANCODE_E, // VirtualKey.E -- 69
slouken@8582
   115
    SDL_SCANCODE_F, // VirtualKey.F -- 70
slouken@8582
   116
    SDL_SCANCODE_G, // VirtualKey.G -- 71
slouken@8582
   117
    SDL_SCANCODE_H, // VirtualKey.H -- 72
slouken@8582
   118
    SDL_SCANCODE_I, // VirtualKey.I -- 73
slouken@8582
   119
    SDL_SCANCODE_J, // VirtualKey.J -- 74
slouken@8582
   120
    SDL_SCANCODE_K, // VirtualKey.K -- 75
slouken@8582
   121
    SDL_SCANCODE_L, // VirtualKey.L -- 76
slouken@8582
   122
    SDL_SCANCODE_M, // VirtualKey.M -- 77
slouken@8582
   123
    SDL_SCANCODE_N, // VirtualKey.N -- 78
slouken@8582
   124
    SDL_SCANCODE_O, // VirtualKey.O -- 79
slouken@8582
   125
    SDL_SCANCODE_P, // VirtualKey.P -- 80
slouken@8582
   126
    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
slouken@8582
   127
    SDL_SCANCODE_R, // VirtualKey.R -- 82
slouken@8582
   128
    SDL_SCANCODE_S, // VirtualKey.S -- 83
slouken@8582
   129
    SDL_SCANCODE_T, // VirtualKey.T -- 84
slouken@8582
   130
    SDL_SCANCODE_U, // VirtualKey.U -- 85
slouken@8582
   131
    SDL_SCANCODE_V, // VirtualKey.V -- 86
slouken@8582
   132
    SDL_SCANCODE_W, // VirtualKey.W -- 87
slouken@8582
   133
    SDL_SCANCODE_X, // VirtualKey.X -- 88
slouken@8582
   134
    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
slouken@8582
   135
    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
slouken@8582
   136
    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
slouken@8582
   137
    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
slouken@8582
   138
    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
slouken@8582
   139
    SDL_SCANCODE_UNKNOWN, // -- 94
slouken@8582
   140
    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
slouken@8582
   141
    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
slouken@8582
   142
    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
slouken@8582
   143
    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
slouken@8582
   144
    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
slouken@8582
   145
    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
slouken@8582
   146
    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
slouken@8582
   147
    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
slouken@8582
   148
    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
slouken@8582
   149
    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
slouken@8582
   150
    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
slouken@8582
   151
    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
slouken@8582
   152
    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
slouken@8582
   153
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
slouken@8582
   154
    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
slouken@8582
   155
    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
slouken@8582
   156
    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
slouken@8582
   157
    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
slouken@8582
   158
    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
slouken@8582
   159
    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
slouken@8582
   160
    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
slouken@8582
   161
    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
slouken@8582
   162
    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
slouken@8582
   163
    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
slouken@8582
   164
    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
slouken@8582
   165
    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
slouken@8582
   166
    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
slouken@8582
   167
    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
slouken@8582
   168
    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
slouken@8582
   169
    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
slouken@8582
   170
    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
slouken@8582
   171
    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
slouken@8582
   172
    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
slouken@8582
   173
    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
slouken@8582
   174
    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
slouken@8582
   175
    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
slouken@8582
   176
    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
slouken@8582
   177
    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
slouken@8582
   178
    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
slouken@8582
   179
    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
slouken@8582
   180
    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
slouken@8582
   181
    SDL_SCANCODE_UNKNOWN, // -- 136
slouken@8582
   182
    SDL_SCANCODE_UNKNOWN, // -- 137
slouken@8582
   183
    SDL_SCANCODE_UNKNOWN, // -- 138
slouken@8582
   184
    SDL_SCANCODE_UNKNOWN, // -- 139
slouken@8582
   185
    SDL_SCANCODE_UNKNOWN, // -- 140
slouken@8582
   186
    SDL_SCANCODE_UNKNOWN, // -- 141
slouken@8582
   187
    SDL_SCANCODE_UNKNOWN, // -- 142
slouken@8582
   188
    SDL_SCANCODE_UNKNOWN, // -- 143
slouken@8582
   189
    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
slouken@8582
   190
    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
slouken@8582
   191
    SDL_SCANCODE_UNKNOWN, // -- 146
slouken@8582
   192
    SDL_SCANCODE_UNKNOWN, // -- 147
slouken@8582
   193
    SDL_SCANCODE_UNKNOWN, // -- 148
slouken@8582
   194
    SDL_SCANCODE_UNKNOWN, // -- 149
slouken@8582
   195
    SDL_SCANCODE_UNKNOWN, // -- 150
slouken@8582
   196
    SDL_SCANCODE_UNKNOWN, // -- 151
slouken@8582
   197
    SDL_SCANCODE_UNKNOWN, // -- 152
slouken@8582
   198
    SDL_SCANCODE_UNKNOWN, // -- 153
slouken@8582
   199
    SDL_SCANCODE_UNKNOWN, // -- 154
slouken@8582
   200
    SDL_SCANCODE_UNKNOWN, // -- 155
slouken@8582
   201
    SDL_SCANCODE_UNKNOWN, // -- 156
slouken@8582
   202
    SDL_SCANCODE_UNKNOWN, // -- 157
slouken@8582
   203
    SDL_SCANCODE_UNKNOWN, // -- 158
slouken@8582
   204
    SDL_SCANCODE_UNKNOWN, // -- 159
slouken@8582
   205
    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
slouken@8582
   206
    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
slouken@8582
   207
    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
slouken@8582
   208
    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
slouken@8582
   209
    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
slouken@8582
   210
    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
dludwig@8701
   211
    SDL_SCANCODE_AC_BACK, // VirtualKey.GoBack -- 166 : The go back key.
dludwig@8701
   212
    SDL_SCANCODE_AC_FORWARD, // VirtualKey.GoForward -- 167 : The go forward key.
dludwig@8701
   213
    SDL_SCANCODE_AC_REFRESH, // VirtualKey.Refresh -- 168 : The refresh key.
dludwig@8701
   214
    SDL_SCANCODE_AC_STOP, // VirtualKey.Stop -- 169 : The stop key.
dludwig@8701
   215
    SDL_SCANCODE_AC_SEARCH, // VirtualKey.Search -- 170 : The search key.
dludwig@8701
   216
    SDL_SCANCODE_AC_BOOKMARKS, // VirtualKey.Favorites -- 171 : The favorites key.
dludwig@8701
   217
    SDL_SCANCODE_AC_HOME // VirtualKey.GoHome -- 172 : The go home key.
slouken@8582
   218
};
slouken@8582
   219
slouken@8582
   220
static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
slouken@8582
   221
slouken@8582
   222
static SDL_Scancode
slouken@8582
   223
TranslateKeycode(int keycode)
slouken@8582
   224
{
slouken@8582
   225
    if (WinRT_Unofficial_Keycodes.empty()) {
dludwig@8701
   226
        /* Set up a table of keycodes that aren't listed in WinRT's
dludwig@8701
   227
         * VirtualKey enum.
dludwig@8701
   228
         */
dludwig@8701
   229
dludwig@8701
   230
        WinRT_Unofficial_Keycodes[173] = SDL_SCANCODE_MUTE;
dludwig@8701
   231
        WinRT_Unofficial_Keycodes[174] = SDL_SCANCODE_VOLUMEDOWN;
dludwig@8701
   232
        WinRT_Unofficial_Keycodes[175] = SDL_SCANCODE_VOLUMEUP;
dludwig@8701
   233
        WinRT_Unofficial_Keycodes[176] = SDL_SCANCODE_AUDIONEXT;
dludwig@8701
   234
        WinRT_Unofficial_Keycodes[177] = SDL_SCANCODE_AUDIOPREV;
dludwig@8701
   235
        // WinRT_Unofficial_Keycodes[178] = ;
dludwig@8701
   236
        WinRT_Unofficial_Keycodes[179] = SDL_SCANCODE_AUDIOPLAY;
dludwig@8701
   237
        WinRT_Unofficial_Keycodes[180] = SDL_SCANCODE_MAIL;
dludwig@8701
   238
        WinRT_Unofficial_Keycodes[181] = SDL_SCANCODE_MEDIASELECT;
dludwig@8701
   239
        // WinRT_Unofficial_Keycodes[182] = ;
dludwig@8701
   240
        WinRT_Unofficial_Keycodes[183] = SDL_SCANCODE_CALCULATOR;
dludwig@8701
   241
        // WinRT_Unofficial_Keycodes[184] = ;
dludwig@8701
   242
        // WinRT_Unofficial_Keycodes[185] = ;
dludwig@8701
   243
        WinRT_Unofficial_Keycodes[186] = SDL_SCANCODE_SEMICOLON;
dludwig@8701
   244
        WinRT_Unofficial_Keycodes[187] = SDL_SCANCODE_EQUALS;
dludwig@8701
   245
        WinRT_Unofficial_Keycodes[188] = SDL_SCANCODE_COMMA;
dludwig@8701
   246
        WinRT_Unofficial_Keycodes[189] = SDL_SCANCODE_MINUS;
dludwig@8701
   247
        WinRT_Unofficial_Keycodes[190] = SDL_SCANCODE_PERIOD;
dludwig@8701
   248
        WinRT_Unofficial_Keycodes[191] = SDL_SCANCODE_SLASH;
dludwig@8701
   249
        WinRT_Unofficial_Keycodes[192] = SDL_SCANCODE_GRAVE;
dludwig@8701
   250
        // ?
dludwig@8701
   251
        // ...
dludwig@8701
   252
        // ?
dludwig@8701
   253
        WinRT_Unofficial_Keycodes[219] = SDL_SCANCODE_LEFTBRACKET;
dludwig@8701
   254
        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_BACKSLASH;
dludwig@8701
   255
        WinRT_Unofficial_Keycodes[221] = SDL_SCANCODE_RIGHTBRACKET;
dludwig@8701
   256
        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_APOSTROPHE;
slouken@8582
   257
    }
slouken@8582
   258
slouken@8582
   259
    /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
slouken@8582
   260
       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
slouken@8582
   261
       If that fails, fall back to a Win32 virtual key.
slouken@8582
   262
    */
slouken@8582
   263
    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
slouken@8582
   264
    //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
slouken@8582
   265
    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
slouken@8582
   266
    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
slouken@8582
   267
        scancode = WinRT_Official_Keycodes[keycode];
slouken@8582
   268
    }
slouken@8582
   269
    if (scancode == SDL_SCANCODE_UNKNOWN) {
slouken@8582
   270
        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
slouken@8582
   271
            scancode = WinRT_Unofficial_Keycodes[keycode];
slouken@8582
   272
        }
slouken@8582
   273
    }
slouken@8582
   274
    if (scancode == SDL_SCANCODE_UNKNOWN) {
slouken@8582
   275
        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
slouken@8582
   276
    }
slouken@8582
   277
    return scancode;
slouken@8582
   278
}
slouken@8582
   279
slouken@8582
   280
void
slouken@8582
   281
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
slouken@8582
   282
{
slouken@8582
   283
    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
slouken@8582
   284
#if 0
slouken@8582
   285
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
slouken@8582
   286
    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
slouken@8582
   287
        (args->Handled ? "1" : "0"),
slouken@8582
   288
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
slouken@8582
   289
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
slouken@8582
   290
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
slouken@8582
   291
        args->KeyStatus.RepeatCount,
slouken@8582
   292
        args->KeyStatus.ScanCode,
slouken@8582
   293
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
slouken@8582
   294
        args->VirtualKey,
slouken@8582
   295
        sdlScancode,
slouken@8582
   296
        SDL_GetScancodeName(sdlScancode),
slouken@8582
   297
        keycode,
slouken@8582
   298
        SDL_GetKeyName(keycode));
slouken@8582
   299
    //args->Handled = true;
slouken@8582
   300
    //VirtualKey vkey = args->VirtualKey;
slouken@8582
   301
#endif
slouken@8582
   302
    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
slouken@8582
   303
}
slouken@8582
   304
slouken@8582
   305
void
slouken@8582
   306
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
slouken@8582
   307
{
slouken@8582
   308
    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
slouken@8582
   309
#if 0
slouken@8582
   310
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
slouken@8582
   311
    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
slouken@8582
   312
        (args->Handled ? "1" : "0"),
slouken@8582
   313
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
slouken@8582
   314
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
slouken@8582
   315
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
slouken@8582
   316
        args->KeyStatus.RepeatCount,
slouken@8582
   317
        args->KeyStatus.ScanCode,
slouken@8582
   318
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
slouken@8582
   319
        args->VirtualKey,
slouken@8582
   320
        sdlScancode,
slouken@8582
   321
        SDL_GetScancodeName(sdlScancode),
slouken@8582
   322
        keycode,
slouken@8582
   323
        SDL_GetKeyName(keycode));
slouken@8582
   324
    //args->Handled = true;
slouken@8582
   325
#endif
slouken@8582
   326
    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
slouken@8582
   327
}
slouken@8582
   328
slouken@8582
   329
#endif // SDL_VIDEO_DRIVER_WINRT