src/video/winrt/SDL_winrtkeyboard.cpp
changeset 8582 c3e9a2b93517
parent 8494 5d165785918d
child 8600 092802455aed
     1.1 --- a/src/video/winrt/SDL_winrtkeyboard.cpp	Tue Mar 04 19:49:11 2014 -0500
     1.2 +++ b/src/video/winrt/SDL_winrtkeyboard.cpp	Sun Mar 09 11:06:11 2014 -0700
     1.3 @@ -1,301 +1,301 @@
     1.4 -/*
     1.5 -  Simple DirectMedia Layer
     1.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 -
     1.8 -  This software is provided 'as-is', without any express or implied
     1.9 -  warranty.  In no event will the authors be held liable for any damages
    1.10 -  arising from the use of this software.
    1.11 -
    1.12 -  Permission is granted to anyone to use this software for any purpose,
    1.13 -  including commercial applications, and to alter it and redistribute it
    1.14 -  freely, subject to the following restrictions:
    1.15 -
    1.16 -  1. The origin of this software must not be misrepresented; you must not
    1.17 -     claim that you wrote the original software. If you use this software
    1.18 -     in a product, an acknowledgment in the product documentation would be
    1.19 -     appreciated but is not required.
    1.20 -  2. Altered source versions must be plainly marked as such, and must not be
    1.21 -     misrepresented as being the original software.
    1.22 -  3. This notice may not be removed or altered from any source distribution.
    1.23 -*/
    1.24 +/*
    1.25 +  Simple DirectMedia Layer
    1.26 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    1.27 +
    1.28 +  This software is provided 'as-is', without any express or implied
    1.29 +  warranty.  In no event will the authors be held liable for any damages
    1.30 +  arising from the use of this software.
    1.31 +
    1.32 +  Permission is granted to anyone to use this software for any purpose,
    1.33 +  including commercial applications, and to alter it and redistribute it
    1.34 +  freely, subject to the following restrictions:
    1.35 +
    1.36 +  1. The origin of this software must not be misrepresented; you must not
    1.37 +     claim that you wrote the original software. If you use this software
    1.38 +     in a product, an acknowledgment in the product documentation would be
    1.39 +     appreciated but is not required.
    1.40 +  2. Altered source versions must be plainly marked as such, and must not be
    1.41 +     misrepresented as being the original software.
    1.42 +  3. This notice may not be removed or altered from any source distribution.
    1.43 +*/
    1.44  #include "SDL_config.h"
    1.45 -
    1.46 -#if SDL_VIDEO_DRIVER_WINRT
    1.47 -
    1.48 -/* Standard C++11 includes */
    1.49 -#include <unordered_map>
    1.50 -
    1.51 -
    1.52 -/* Windows-specific includes */
    1.53 -#include <Windows.h>
    1.54 -#include <agile.h>
    1.55 -
    1.56 -
    1.57 -/* SDL-specific includes */
    1.58 -#include <SDL.h>
    1.59 -#include "SDL_winrtevents_c.h"
    1.60 -
    1.61 -extern "C" {
    1.62 -#include "../../events/scancodes_windows.h"
    1.63 -#include "../../events/SDL_keyboard_c.h"
    1.64 -}
    1.65 -
    1.66 -
    1.67 -static SDL_Scancode WinRT_Official_Keycodes[] = {
    1.68 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
    1.69 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
    1.70 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
    1.71 -    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
    1.72 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
    1.73 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
    1.74 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
    1.75 -    SDL_SCANCODE_UNKNOWN, // -- 7
    1.76 -    SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
    1.77 -    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
    1.78 -    SDL_SCANCODE_UNKNOWN, // -- 10
    1.79 -    SDL_SCANCODE_UNKNOWN, // -- 11
    1.80 -    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
    1.81 -    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
    1.82 -    SDL_SCANCODE_UNKNOWN, // -- 14
    1.83 -    SDL_SCANCODE_UNKNOWN, // -- 15
    1.84 -    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
    1.85 -    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
    1.86 -    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
    1.87 -    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
    1.88 -    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
    1.89 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
    1.90 -    SDL_SCANCODE_UNKNOWN, // -- 22
    1.91 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
    1.92 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
    1.93 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
    1.94 -    SDL_SCANCODE_UNKNOWN, // -- 26
    1.95 -    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
    1.96 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
    1.97 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
    1.98 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
    1.99 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
   1.100 -    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
   1.101 -    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
   1.102 -    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
   1.103 -    SDL_SCANCODE_END, // VirtualKey.End -- 35
   1.104 -    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
   1.105 -    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
   1.106 -    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
   1.107 -    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
   1.108 -    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
   1.109 -    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
   1.110 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
   1.111 -    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
   1.112 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
   1.113 -    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
   1.114 -    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
   1.115 -    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
   1.116 -    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
   1.117 -    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
   1.118 -    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
   1.119 -    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
   1.120 -    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
   1.121 -    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
   1.122 -    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
   1.123 -    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
   1.124 -    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
   1.125 -    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
   1.126 -    SDL_SCANCODE_UNKNOWN, // -- 58
   1.127 -    SDL_SCANCODE_UNKNOWN, // -- 59
   1.128 -    SDL_SCANCODE_UNKNOWN, // -- 60
   1.129 -    SDL_SCANCODE_UNKNOWN, // -- 61
   1.130 -    SDL_SCANCODE_UNKNOWN, // -- 62
   1.131 -    SDL_SCANCODE_UNKNOWN, // -- 63
   1.132 -    SDL_SCANCODE_UNKNOWN, // -- 64
   1.133 -    SDL_SCANCODE_A, // VirtualKey.A -- 65
   1.134 -    SDL_SCANCODE_B, // VirtualKey.B -- 66
   1.135 -    SDL_SCANCODE_C, // VirtualKey.C -- 67
   1.136 -    SDL_SCANCODE_D, // VirtualKey.D -- 68
   1.137 -    SDL_SCANCODE_E, // VirtualKey.E -- 69
   1.138 -    SDL_SCANCODE_F, // VirtualKey.F -- 70
   1.139 -    SDL_SCANCODE_G, // VirtualKey.G -- 71
   1.140 -    SDL_SCANCODE_H, // VirtualKey.H -- 72
   1.141 -    SDL_SCANCODE_I, // VirtualKey.I -- 73
   1.142 -    SDL_SCANCODE_J, // VirtualKey.J -- 74
   1.143 -    SDL_SCANCODE_K, // VirtualKey.K -- 75
   1.144 -    SDL_SCANCODE_L, // VirtualKey.L -- 76
   1.145 -    SDL_SCANCODE_M, // VirtualKey.M -- 77
   1.146 -    SDL_SCANCODE_N, // VirtualKey.N -- 78
   1.147 -    SDL_SCANCODE_O, // VirtualKey.O -- 79
   1.148 -    SDL_SCANCODE_P, // VirtualKey.P -- 80
   1.149 -    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
   1.150 -    SDL_SCANCODE_R, // VirtualKey.R -- 82
   1.151 -    SDL_SCANCODE_S, // VirtualKey.S -- 83
   1.152 -    SDL_SCANCODE_T, // VirtualKey.T -- 84
   1.153 -    SDL_SCANCODE_U, // VirtualKey.U -- 85
   1.154 -    SDL_SCANCODE_V, // VirtualKey.V -- 86
   1.155 -    SDL_SCANCODE_W, // VirtualKey.W -- 87
   1.156 -    SDL_SCANCODE_X, // VirtualKey.X -- 88
   1.157 -    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
   1.158 -    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
   1.159 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
   1.160 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
   1.161 -    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
   1.162 -    SDL_SCANCODE_UNKNOWN, // -- 94
   1.163 -    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
   1.164 -    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
   1.165 -    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
   1.166 -    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
   1.167 -    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
   1.168 -    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
   1.169 -    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
   1.170 -    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
   1.171 -    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
   1.172 -    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
   1.173 -    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
   1.174 -    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
   1.175 -    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
   1.176 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
   1.177 -    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
   1.178 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
   1.179 -    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
   1.180 -    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
   1.181 -    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
   1.182 -    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
   1.183 -    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
   1.184 -    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
   1.185 -    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
   1.186 -    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
   1.187 -    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
   1.188 -    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
   1.189 -    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
   1.190 -    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
   1.191 -    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
   1.192 -    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
   1.193 -    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
   1.194 -    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
   1.195 -    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
   1.196 -    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
   1.197 -    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
   1.198 -    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
   1.199 -    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
   1.200 -    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
   1.201 -    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
   1.202 -    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
   1.203 -    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
   1.204 -    SDL_SCANCODE_UNKNOWN, // -- 136
   1.205 -    SDL_SCANCODE_UNKNOWN, // -- 137
   1.206 -    SDL_SCANCODE_UNKNOWN, // -- 138
   1.207 -    SDL_SCANCODE_UNKNOWN, // -- 139
   1.208 -    SDL_SCANCODE_UNKNOWN, // -- 140
   1.209 -    SDL_SCANCODE_UNKNOWN, // -- 141
   1.210 -    SDL_SCANCODE_UNKNOWN, // -- 142
   1.211 -    SDL_SCANCODE_UNKNOWN, // -- 143
   1.212 -    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
   1.213 -    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
   1.214 -    SDL_SCANCODE_UNKNOWN, // -- 146
   1.215 -    SDL_SCANCODE_UNKNOWN, // -- 147
   1.216 -    SDL_SCANCODE_UNKNOWN, // -- 148
   1.217 -    SDL_SCANCODE_UNKNOWN, // -- 149
   1.218 -    SDL_SCANCODE_UNKNOWN, // -- 150
   1.219 -    SDL_SCANCODE_UNKNOWN, // -- 151
   1.220 -    SDL_SCANCODE_UNKNOWN, // -- 152
   1.221 -    SDL_SCANCODE_UNKNOWN, // -- 153
   1.222 -    SDL_SCANCODE_UNKNOWN, // -- 154
   1.223 -    SDL_SCANCODE_UNKNOWN, // -- 155
   1.224 -    SDL_SCANCODE_UNKNOWN, // -- 156
   1.225 -    SDL_SCANCODE_UNKNOWN, // -- 157
   1.226 -    SDL_SCANCODE_UNKNOWN, // -- 158
   1.227 -    SDL_SCANCODE_UNKNOWN, // -- 159
   1.228 -    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
   1.229 -    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
   1.230 -    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
   1.231 -    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
   1.232 -    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
   1.233 -    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
   1.234 -};
   1.235 -
   1.236 -static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
   1.237 -
   1.238 -static SDL_Scancode
   1.239 -TranslateKeycode(int keycode)
   1.240 -{
   1.241 -    if (WinRT_Unofficial_Keycodes.empty()) {
   1.242 -        /* Set up a table of undocumented (by Microsoft), WinRT-specific,
   1.243 -           key codes: */
   1.244 -        // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
   1.245 -        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
   1.246 -        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
   1.247 -    }
   1.248 -
   1.249 -    /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
   1.250 -       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
   1.251 -       If that fails, fall back to a Win32 virtual key.
   1.252 -    */
   1.253 -    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
   1.254 -    //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
   1.255 -    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
   1.256 -    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
   1.257 -        scancode = WinRT_Official_Keycodes[keycode];
   1.258 -    }
   1.259 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.260 -        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
   1.261 -            scancode = WinRT_Unofficial_Keycodes[keycode];
   1.262 -        }
   1.263 -    }
   1.264 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.265 -        if (keycode < SDL_arraysize(windows_scancode_table)) {
   1.266 -            scancode = windows_scancode_table[keycode];
   1.267 -        }
   1.268 -    }
   1.269 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.270 -        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
   1.271 -    }
   1.272 -    return scancode;
   1.273 -}
   1.274 -
   1.275 -void
   1.276 -WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
   1.277 -{
   1.278 -    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   1.279 -#if 0
   1.280 -    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   1.281 -    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",
   1.282 -        (args->Handled ? "1" : "0"),
   1.283 -        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   1.284 -        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   1.285 -        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   1.286 -        args->KeyStatus.RepeatCount,
   1.287 -        args->KeyStatus.ScanCode,
   1.288 -        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   1.289 -        args->VirtualKey,
   1.290 -        sdlScancode,
   1.291 -        SDL_GetScancodeName(sdlScancode),
   1.292 -        keycode,
   1.293 -        SDL_GetKeyName(keycode));
   1.294 -    //args->Handled = true;
   1.295 -    //VirtualKey vkey = args->VirtualKey;
   1.296 -#endif
   1.297 -    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
   1.298 -}
   1.299 -
   1.300 -void
   1.301 -WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
   1.302 -{
   1.303 -    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   1.304 -#if 0
   1.305 -    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   1.306 -    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",
   1.307 -        (args->Handled ? "1" : "0"),
   1.308 -        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   1.309 -        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   1.310 -        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   1.311 -        args->KeyStatus.RepeatCount,
   1.312 -        args->KeyStatus.ScanCode,
   1.313 -        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   1.314 -        args->VirtualKey,
   1.315 -        sdlScancode,
   1.316 -        SDL_GetScancodeName(sdlScancode),
   1.317 -        keycode,
   1.318 -        SDL_GetKeyName(keycode));
   1.319 -    //args->Handled = true;
   1.320 -#endif
   1.321 -    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
   1.322 -}
   1.323 -
   1.324 -#endif // SDL_VIDEO_DRIVER_WINRT
   1.325 +
   1.326 +#if SDL_VIDEO_DRIVER_WINRT
   1.327 +
   1.328 +/* Standard C++11 includes */
   1.329 +#include <unordered_map>
   1.330 +
   1.331 +
   1.332 +/* Windows-specific includes */
   1.333 +#include <Windows.h>
   1.334 +#include <agile.h>
   1.335 +
   1.336 +
   1.337 +/* SDL-specific includes */
   1.338 +#include <SDL.h>
   1.339 +#include "SDL_winrtevents_c.h"
   1.340 +
   1.341 +extern "C" {
   1.342 +#include "../../events/scancodes_windows.h"
   1.343 +#include "../../events/SDL_keyboard_c.h"
   1.344 +}
   1.345 +
   1.346 +
   1.347 +static SDL_Scancode WinRT_Official_Keycodes[] = {
   1.348 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
   1.349 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
   1.350 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
   1.351 +    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
   1.352 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
   1.353 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
   1.354 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
   1.355 +    SDL_SCANCODE_UNKNOWN, // -- 7
   1.356 +    SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
   1.357 +    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
   1.358 +    SDL_SCANCODE_UNKNOWN, // -- 10
   1.359 +    SDL_SCANCODE_UNKNOWN, // -- 11
   1.360 +    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
   1.361 +    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
   1.362 +    SDL_SCANCODE_UNKNOWN, // -- 14
   1.363 +    SDL_SCANCODE_UNKNOWN, // -- 15
   1.364 +    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
   1.365 +    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
   1.366 +    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
   1.367 +    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
   1.368 +    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
   1.369 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
   1.370 +    SDL_SCANCODE_UNKNOWN, // -- 22
   1.371 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
   1.372 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
   1.373 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
   1.374 +    SDL_SCANCODE_UNKNOWN, // -- 26
   1.375 +    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
   1.376 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
   1.377 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
   1.378 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
   1.379 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
   1.380 +    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
   1.381 +    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
   1.382 +    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
   1.383 +    SDL_SCANCODE_END, // VirtualKey.End -- 35
   1.384 +    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
   1.385 +    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
   1.386 +    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
   1.387 +    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
   1.388 +    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
   1.389 +    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
   1.390 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
   1.391 +    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
   1.392 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
   1.393 +    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
   1.394 +    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
   1.395 +    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
   1.396 +    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
   1.397 +    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
   1.398 +    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
   1.399 +    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
   1.400 +    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
   1.401 +    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
   1.402 +    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
   1.403 +    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
   1.404 +    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
   1.405 +    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
   1.406 +    SDL_SCANCODE_UNKNOWN, // -- 58
   1.407 +    SDL_SCANCODE_UNKNOWN, // -- 59
   1.408 +    SDL_SCANCODE_UNKNOWN, // -- 60
   1.409 +    SDL_SCANCODE_UNKNOWN, // -- 61
   1.410 +    SDL_SCANCODE_UNKNOWN, // -- 62
   1.411 +    SDL_SCANCODE_UNKNOWN, // -- 63
   1.412 +    SDL_SCANCODE_UNKNOWN, // -- 64
   1.413 +    SDL_SCANCODE_A, // VirtualKey.A -- 65
   1.414 +    SDL_SCANCODE_B, // VirtualKey.B -- 66
   1.415 +    SDL_SCANCODE_C, // VirtualKey.C -- 67
   1.416 +    SDL_SCANCODE_D, // VirtualKey.D -- 68
   1.417 +    SDL_SCANCODE_E, // VirtualKey.E -- 69
   1.418 +    SDL_SCANCODE_F, // VirtualKey.F -- 70
   1.419 +    SDL_SCANCODE_G, // VirtualKey.G -- 71
   1.420 +    SDL_SCANCODE_H, // VirtualKey.H -- 72
   1.421 +    SDL_SCANCODE_I, // VirtualKey.I -- 73
   1.422 +    SDL_SCANCODE_J, // VirtualKey.J -- 74
   1.423 +    SDL_SCANCODE_K, // VirtualKey.K -- 75
   1.424 +    SDL_SCANCODE_L, // VirtualKey.L -- 76
   1.425 +    SDL_SCANCODE_M, // VirtualKey.M -- 77
   1.426 +    SDL_SCANCODE_N, // VirtualKey.N -- 78
   1.427 +    SDL_SCANCODE_O, // VirtualKey.O -- 79
   1.428 +    SDL_SCANCODE_P, // VirtualKey.P -- 80
   1.429 +    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
   1.430 +    SDL_SCANCODE_R, // VirtualKey.R -- 82
   1.431 +    SDL_SCANCODE_S, // VirtualKey.S -- 83
   1.432 +    SDL_SCANCODE_T, // VirtualKey.T -- 84
   1.433 +    SDL_SCANCODE_U, // VirtualKey.U -- 85
   1.434 +    SDL_SCANCODE_V, // VirtualKey.V -- 86
   1.435 +    SDL_SCANCODE_W, // VirtualKey.W -- 87
   1.436 +    SDL_SCANCODE_X, // VirtualKey.X -- 88
   1.437 +    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
   1.438 +    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
   1.439 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
   1.440 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
   1.441 +    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
   1.442 +    SDL_SCANCODE_UNKNOWN, // -- 94
   1.443 +    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
   1.444 +    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
   1.445 +    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
   1.446 +    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
   1.447 +    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
   1.448 +    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
   1.449 +    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
   1.450 +    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
   1.451 +    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
   1.452 +    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
   1.453 +    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
   1.454 +    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
   1.455 +    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
   1.456 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
   1.457 +    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
   1.458 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
   1.459 +    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
   1.460 +    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
   1.461 +    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
   1.462 +    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
   1.463 +    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
   1.464 +    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
   1.465 +    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
   1.466 +    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
   1.467 +    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
   1.468 +    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
   1.469 +    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
   1.470 +    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
   1.471 +    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
   1.472 +    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
   1.473 +    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
   1.474 +    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
   1.475 +    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
   1.476 +    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
   1.477 +    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
   1.478 +    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
   1.479 +    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
   1.480 +    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
   1.481 +    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
   1.482 +    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
   1.483 +    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
   1.484 +    SDL_SCANCODE_UNKNOWN, // -- 136
   1.485 +    SDL_SCANCODE_UNKNOWN, // -- 137
   1.486 +    SDL_SCANCODE_UNKNOWN, // -- 138
   1.487 +    SDL_SCANCODE_UNKNOWN, // -- 139
   1.488 +    SDL_SCANCODE_UNKNOWN, // -- 140
   1.489 +    SDL_SCANCODE_UNKNOWN, // -- 141
   1.490 +    SDL_SCANCODE_UNKNOWN, // -- 142
   1.491 +    SDL_SCANCODE_UNKNOWN, // -- 143
   1.492 +    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
   1.493 +    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
   1.494 +    SDL_SCANCODE_UNKNOWN, // -- 146
   1.495 +    SDL_SCANCODE_UNKNOWN, // -- 147
   1.496 +    SDL_SCANCODE_UNKNOWN, // -- 148
   1.497 +    SDL_SCANCODE_UNKNOWN, // -- 149
   1.498 +    SDL_SCANCODE_UNKNOWN, // -- 150
   1.499 +    SDL_SCANCODE_UNKNOWN, // -- 151
   1.500 +    SDL_SCANCODE_UNKNOWN, // -- 152
   1.501 +    SDL_SCANCODE_UNKNOWN, // -- 153
   1.502 +    SDL_SCANCODE_UNKNOWN, // -- 154
   1.503 +    SDL_SCANCODE_UNKNOWN, // -- 155
   1.504 +    SDL_SCANCODE_UNKNOWN, // -- 156
   1.505 +    SDL_SCANCODE_UNKNOWN, // -- 157
   1.506 +    SDL_SCANCODE_UNKNOWN, // -- 158
   1.507 +    SDL_SCANCODE_UNKNOWN, // -- 159
   1.508 +    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
   1.509 +    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
   1.510 +    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
   1.511 +    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
   1.512 +    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
   1.513 +    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
   1.514 +};
   1.515 +
   1.516 +static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
   1.517 +
   1.518 +static SDL_Scancode
   1.519 +TranslateKeycode(int keycode)
   1.520 +{
   1.521 +    if (WinRT_Unofficial_Keycodes.empty()) {
   1.522 +        /* Set up a table of undocumented (by Microsoft), WinRT-specific,
   1.523 +           key codes: */
   1.524 +        // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
   1.525 +        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
   1.526 +        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
   1.527 +    }
   1.528 +
   1.529 +    /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
   1.530 +       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
   1.531 +       If that fails, fall back to a Win32 virtual key.
   1.532 +    */
   1.533 +    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
   1.534 +    //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
   1.535 +    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
   1.536 +    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
   1.537 +        scancode = WinRT_Official_Keycodes[keycode];
   1.538 +    }
   1.539 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.540 +        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
   1.541 +            scancode = WinRT_Unofficial_Keycodes[keycode];
   1.542 +        }
   1.543 +    }
   1.544 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.545 +        if (keycode < SDL_arraysize(windows_scancode_table)) {
   1.546 +            scancode = windows_scancode_table[keycode];
   1.547 +        }
   1.548 +    }
   1.549 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.550 +        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
   1.551 +    }
   1.552 +    return scancode;
   1.553 +}
   1.554 +
   1.555 +void
   1.556 +WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
   1.557 +{
   1.558 +    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   1.559 +#if 0
   1.560 +    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   1.561 +    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",
   1.562 +        (args->Handled ? "1" : "0"),
   1.563 +        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   1.564 +        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   1.565 +        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   1.566 +        args->KeyStatus.RepeatCount,
   1.567 +        args->KeyStatus.ScanCode,
   1.568 +        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   1.569 +        args->VirtualKey,
   1.570 +        sdlScancode,
   1.571 +        SDL_GetScancodeName(sdlScancode),
   1.572 +        keycode,
   1.573 +        SDL_GetKeyName(keycode));
   1.574 +    //args->Handled = true;
   1.575 +    //VirtualKey vkey = args->VirtualKey;
   1.576 +#endif
   1.577 +    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
   1.578 +}
   1.579 +
   1.580 +void
   1.581 +WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
   1.582 +{
   1.583 +    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   1.584 +#if 0
   1.585 +    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   1.586 +    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",
   1.587 +        (args->Handled ? "1" : "0"),
   1.588 +        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   1.589 +        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   1.590 +        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   1.591 +        args->KeyStatus.RepeatCount,
   1.592 +        args->KeyStatus.ScanCode,
   1.593 +        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   1.594 +        args->VirtualKey,
   1.595 +        sdlScancode,
   1.596 +        SDL_GetScancodeName(sdlScancode),
   1.597 +        keycode,
   1.598 +        SDL_GetKeyName(keycode));
   1.599 +    //args->Handled = true;
   1.600 +#endif
   1.601 +    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
   1.602 +}
   1.603 +
   1.604 +#endif // SDL_VIDEO_DRIVER_WINRT