src/video/winrt/SDL_winrtkeyboard.cpp
author David Ludwig <dludwig@pobox.com>
Wed, 26 Nov 2014 21:34:15 -0500
changeset 9240 dc4ad21d8596
parent 9193 5ca521b8486d
child 9619 b94b6d0bff0f
permissions -rw-r--r--
WinRT: added initial SDL_TEXTINPUT support

Further support regarding IME and on-screen keyboards is pending, some of
which might not be 100% compatible with other platforms, given WinRT platform
restrictions. An MSDN article at http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx
indicates that on-screen keyboard display requires that the user first tap on
a Windows/XAML text control.

This change adds basic SDL_TEXTINPUT support, with input coming from hardware
keyboards, at a minimum, and without the need for XAML integration (which is
still pending integration into SDL, by and large).
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
/* Windows-specific includes */
slouken@8582
    26
#include <Windows.h>
slouken@8582
    27
#include <agile.h>
slouken@8582
    28
slouken@8582
    29
slouken@8582
    30
/* SDL-specific includes */
slouken@8582
    31
#include <SDL.h>
slouken@8582
    32
#include "SDL_winrtevents_c.h"
slouken@8582
    33
slouken@8582
    34
extern "C" {
slouken@8582
    35
#include "../../events/scancodes_windows.h"
slouken@8582
    36
#include "../../events/SDL_keyboard_c.h"
slouken@8582
    37
}
slouken@8582
    38
slouken@8582
    39
slouken@8582
    40
static SDL_Scancode WinRT_Official_Keycodes[] = {
dludwig@9193
    41
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.None -- 0 */
dludwig@9193
    42
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.LeftButton -- 1 */
dludwig@9193
    43
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.RightButton -- 2 */
dludwig@9193
    44
    SDL_SCANCODE_CANCEL,        /* VirtualKey.Cancel -- 3 */
dludwig@9193
    45
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.MiddleButton -- 4 */
dludwig@9193
    46
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.XButton1 -- 5 */
dludwig@9193
    47
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.XButton2 -- 6 */
dludwig@9193
    48
    SDL_SCANCODE_UNKNOWN,       /* -- 7 */
dludwig@9193
    49
    SDL_SCANCODE_BACKSPACE,     /* VirtualKey.Back -- 8 */
dludwig@9193
    50
    SDL_SCANCODE_TAB,           /* VirtualKey.Tab -- 9 */
dludwig@9193
    51
    SDL_SCANCODE_UNKNOWN,       /* -- 10 */
dludwig@9193
    52
    SDL_SCANCODE_UNKNOWN,       /* -- 11 */
dludwig@9193
    53
    SDL_SCANCODE_CLEAR,         /* VirtualKey.Clear -- 12 */
dludwig@9193
    54
    SDL_SCANCODE_RETURN,        /* VirtualKey.Enter -- 13 */
dludwig@9193
    55
    SDL_SCANCODE_UNKNOWN,       /* -- 14 */
dludwig@9193
    56
    SDL_SCANCODE_UNKNOWN,       /* -- 15 */
dludwig@9193
    57
    SDL_SCANCODE_LSHIFT,        /* VirtualKey.Shift -- 16 */
dludwig@9193
    58
    SDL_SCANCODE_LCTRL,         /* VirtualKey.Control -- 17 */
dludwig@9193
    59
    SDL_SCANCODE_MENU,          /* VirtualKey.Menu -- 18 */
dludwig@9193
    60
    SDL_SCANCODE_PAUSE,         /* VirtualKey.Pause -- 19 */
dludwig@9193
    61
    SDL_SCANCODE_CAPSLOCK,      /* VirtualKey.CapitalLock -- 20 */
dludwig@9193
    62
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Kana or VirtualKey.Hangul -- 21 */
dludwig@9193
    63
    SDL_SCANCODE_UNKNOWN,       /* -- 22 */
dludwig@9193
    64
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Junja -- 23 */
dludwig@9193
    65
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Final -- 24 */
dludwig@9193
    66
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Hanja or VirtualKey.Kanji -- 25 */
dludwig@9193
    67
    SDL_SCANCODE_UNKNOWN,       /* -- 26 */
dludwig@9193
    68
    SDL_SCANCODE_ESCAPE,        /* VirtualKey.Escape -- 27 */
dludwig@9193
    69
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Convert -- 28 */
dludwig@9193
    70
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.NonConvert -- 29 */
dludwig@9193
    71
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Accept -- 30 */
dludwig@9193
    72
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?) */
dludwig@9193
    73
    SDL_SCANCODE_SPACE,         /* VirtualKey.Space -- 32 */
dludwig@9193
    74
    SDL_SCANCODE_PAGEUP,        /* VirtualKey.PageUp -- 33 */
dludwig@9193
    75
    SDL_SCANCODE_PAGEDOWN,      /* VirtualKey.PageDown -- 34 */
dludwig@9193
    76
    SDL_SCANCODE_END,           /* VirtualKey.End -- 35 */
dludwig@9193
    77
    SDL_SCANCODE_HOME,          /* VirtualKey.Home -- 36 */
dludwig@9193
    78
    SDL_SCANCODE_LEFT,          /* VirtualKey.Left -- 37 */
dludwig@9193
    79
    SDL_SCANCODE_UP,            /* VirtualKey.Up -- 38 */
dludwig@9193
    80
    SDL_SCANCODE_RIGHT,         /* VirtualKey.Right -- 39 */
dludwig@9193
    81
    SDL_SCANCODE_DOWN,          /* VirtualKey.Down -- 40 */
dludwig@9193
    82
    SDL_SCANCODE_SELECT,        /* VirtualKey.Select -- 41 */
dludwig@9193
    83
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?) */
dludwig@9193
    84
    SDL_SCANCODE_EXECUTE,       /* VirtualKey.Execute -- 43 */
dludwig@9193
    85
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Snapshot -- 44 */
dludwig@9193
    86
    SDL_SCANCODE_INSERT,        /* VirtualKey.Insert -- 45 */
dludwig@9193
    87
    SDL_SCANCODE_DELETE,        /* VirtualKey.Delete -- 46 */
dludwig@9193
    88
    SDL_SCANCODE_HELP,          /* VirtualKey.Help -- 47 */
dludwig@9193
    89
    SDL_SCANCODE_0,             /* VirtualKey.Number0 -- 48 */
dludwig@9193
    90
    SDL_SCANCODE_1,             /* VirtualKey.Number1 -- 49 */
dludwig@9193
    91
    SDL_SCANCODE_2,             /* VirtualKey.Number2 -- 50 */
dludwig@9193
    92
    SDL_SCANCODE_3,             /* VirtualKey.Number3 -- 51 */
dludwig@9193
    93
    SDL_SCANCODE_4,             /* VirtualKey.Number4 -- 52 */
dludwig@9193
    94
    SDL_SCANCODE_5,             /* VirtualKey.Number5 -- 53 */
dludwig@9193
    95
    SDL_SCANCODE_6,             /* VirtualKey.Number6 -- 54 */
dludwig@9193
    96
    SDL_SCANCODE_7,             /* VirtualKey.Number7 -- 55 */
dludwig@9193
    97
    SDL_SCANCODE_8,             /* VirtualKey.Number8 -- 56 */
dludwig@9193
    98
    SDL_SCANCODE_9,             /* VirtualKey.Number9 -- 57 */
dludwig@9193
    99
    SDL_SCANCODE_UNKNOWN,       /* -- 58 */
dludwig@9193
   100
    SDL_SCANCODE_UNKNOWN,       /* -- 59 */
dludwig@9193
   101
    SDL_SCANCODE_UNKNOWN,       /* -- 60 */
dludwig@9193
   102
    SDL_SCANCODE_UNKNOWN,       /* -- 61 */
dludwig@9193
   103
    SDL_SCANCODE_UNKNOWN,       /* -- 62 */
dludwig@9193
   104
    SDL_SCANCODE_UNKNOWN,       /* -- 63 */
dludwig@9193
   105
    SDL_SCANCODE_UNKNOWN,       /* -- 64 */
dludwig@9193
   106
    SDL_SCANCODE_A,             /* VirtualKey.A -- 65 */
dludwig@9193
   107
    SDL_SCANCODE_B,             /* VirtualKey.B -- 66 */
dludwig@9193
   108
    SDL_SCANCODE_C,             /* VirtualKey.C -- 67 */
dludwig@9193
   109
    SDL_SCANCODE_D,             /* VirtualKey.D -- 68 */
dludwig@9193
   110
    SDL_SCANCODE_E,             /* VirtualKey.E -- 69 */
dludwig@9193
   111
    SDL_SCANCODE_F,             /* VirtualKey.F -- 70 */
dludwig@9193
   112
    SDL_SCANCODE_G,             /* VirtualKey.G -- 71 */
dludwig@9193
   113
    SDL_SCANCODE_H,             /* VirtualKey.H -- 72 */
dludwig@9193
   114
    SDL_SCANCODE_I,             /* VirtualKey.I -- 73 */
dludwig@9193
   115
    SDL_SCANCODE_J,             /* VirtualKey.J -- 74 */
dludwig@9193
   116
    SDL_SCANCODE_K,             /* VirtualKey.K -- 75 */
dludwig@9193
   117
    SDL_SCANCODE_L,             /* VirtualKey.L -- 76 */
dludwig@9193
   118
    SDL_SCANCODE_M,             /* VirtualKey.M -- 77 */
dludwig@9193
   119
    SDL_SCANCODE_N,             /* VirtualKey.N -- 78 */
dludwig@9193
   120
    SDL_SCANCODE_O,             /* VirtualKey.O -- 79 */
dludwig@9193
   121
    SDL_SCANCODE_P,             /* VirtualKey.P -- 80 */
dludwig@9193
   122
    SDL_SCANCODE_Q,             /* VirtualKey.Q -- 81 */
dludwig@9193
   123
    SDL_SCANCODE_R,             /* VirtualKey.R -- 82 */
dludwig@9193
   124
    SDL_SCANCODE_S,             /* VirtualKey.S -- 83 */
dludwig@9193
   125
    SDL_SCANCODE_T,             /* VirtualKey.T -- 84 */
dludwig@9193
   126
    SDL_SCANCODE_U,             /* VirtualKey.U -- 85 */
dludwig@9193
   127
    SDL_SCANCODE_V,             /* VirtualKey.V -- 86 */
dludwig@9193
   128
    SDL_SCANCODE_W,             /* VirtualKey.W -- 87 */
dludwig@9193
   129
    SDL_SCANCODE_X,             /* VirtualKey.X -- 88 */
dludwig@9193
   130
    SDL_SCANCODE_Y,             /* VirtualKey.Y -- 89 */
dludwig@9193
   131
    SDL_SCANCODE_Z,             /* VirtualKey.Z -- 90 */
dludwig@9193
   132
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?) */
dludwig@9193
   133
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?) */
dludwig@9193
   134
    SDL_SCANCODE_APPLICATION,   /* VirtualKey.Application -- 93 */
dludwig@9193
   135
    SDL_SCANCODE_UNKNOWN,       /* -- 94 */
dludwig@9193
   136
    SDL_SCANCODE_SLEEP,         /* VirtualKey.Sleep -- 95 */
dludwig@9193
   137
    SDL_SCANCODE_KP_0,          /* VirtualKey.NumberPad0 -- 96 */
dludwig@9193
   138
    SDL_SCANCODE_KP_1,          /* VirtualKey.NumberPad1 -- 97 */
dludwig@9193
   139
    SDL_SCANCODE_KP_2,          /* VirtualKey.NumberPad2 -- 98 */
dludwig@9193
   140
    SDL_SCANCODE_KP_3,          /* VirtualKey.NumberPad3 -- 99 */
dludwig@9193
   141
    SDL_SCANCODE_KP_4,          /* VirtualKey.NumberPad4 -- 100 */
dludwig@9193
   142
    SDL_SCANCODE_KP_5,          /* VirtualKey.NumberPad5 -- 101 */
dludwig@9193
   143
    SDL_SCANCODE_KP_6,          /* VirtualKey.NumberPad6 -- 102 */
dludwig@9193
   144
    SDL_SCANCODE_KP_7,          /* VirtualKey.NumberPad7 -- 103 */
dludwig@9193
   145
    SDL_SCANCODE_KP_8,          /* VirtualKey.NumberPad8 -- 104 */
dludwig@9193
   146
    SDL_SCANCODE_KP_9,          /* VirtualKey.NumberPad9 -- 105 */
dludwig@9193
   147
    SDL_SCANCODE_KP_MULTIPLY,   /* VirtualKey.Multiply -- 106 */
dludwig@9193
   148
    SDL_SCANCODE_KP_PLUS,       /* VirtualKey.Add -- 107 */
dludwig@9193
   149
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Separator -- 108 */
dludwig@9193
   150
    SDL_SCANCODE_KP_MINUS,      /* VirtualKey.Subtract -- 109 */
dludwig@9193
   151
    SDL_SCANCODE_UNKNOWN,       /* VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?) */
dludwig@9193
   152
    SDL_SCANCODE_KP_DIVIDE,     /* VirtualKey.Divide -- 111 */
dludwig@9193
   153
    SDL_SCANCODE_F1,            /* VirtualKey.F1 -- 112 */
dludwig@9193
   154
    SDL_SCANCODE_F2,            /* VirtualKey.F2 -- 113 */
dludwig@9193
   155
    SDL_SCANCODE_F3,            /* VirtualKey.F3 -- 114 */
dludwig@9193
   156
    SDL_SCANCODE_F4,            /* VirtualKey.F4 -- 115 */
dludwig@9193
   157
    SDL_SCANCODE_F5,            /* VirtualKey.F5 -- 116 */
dludwig@9193
   158
    SDL_SCANCODE_F6,            /* VirtualKey.F6 -- 117 */
dludwig@9193
   159
    SDL_SCANCODE_F7,            /* VirtualKey.F7 -- 118 */
dludwig@9193
   160
    SDL_SCANCODE_F8,            /* VirtualKey.F8 -- 119 */
dludwig@9193
   161
    SDL_SCANCODE_F9,            /* VirtualKey.F9 -- 120 */
dludwig@9193
   162
    SDL_SCANCODE_F10,           /* VirtualKey.F10 -- 121 */
dludwig@9193
   163
    SDL_SCANCODE_F11,           /* VirtualKey.F11 -- 122 */
dludwig@9193
   164
    SDL_SCANCODE_F12,           /* VirtualKey.F12 -- 123 */
dludwig@9193
   165
    SDL_SCANCODE_F13,           /* VirtualKey.F13 -- 124 */
dludwig@9193
   166
    SDL_SCANCODE_F14,           /* VirtualKey.F14 -- 125 */
dludwig@9193
   167
    SDL_SCANCODE_F15,           /* VirtualKey.F15 -- 126 */
dludwig@9193
   168
    SDL_SCANCODE_F16,           /* VirtualKey.F16 -- 127 */
dludwig@9193
   169
    SDL_SCANCODE_F17,           /* VirtualKey.F17 -- 128 */
dludwig@9193
   170
    SDL_SCANCODE_F18,           /* VirtualKey.F18 -- 129 */
dludwig@9193
   171
    SDL_SCANCODE_F19,           /* VirtualKey.F19 -- 130 */
dludwig@9193
   172
    SDL_SCANCODE_F20,           /* VirtualKey.F20 -- 131 */
dludwig@9193
   173
    SDL_SCANCODE_F21,           /* VirtualKey.F21 -- 132 */
dludwig@9193
   174
    SDL_SCANCODE_F22,           /* VirtualKey.F22 -- 133 */
dludwig@9193
   175
    SDL_SCANCODE_F23,           /* VirtualKey.F23 -- 134 */
dludwig@9193
   176
    SDL_SCANCODE_F24,           /* VirtualKey.F24 -- 135 */
dludwig@9193
   177
    SDL_SCANCODE_UNKNOWN,       /* -- 136 */
dludwig@9193
   178
    SDL_SCANCODE_UNKNOWN,       /* -- 137 */
dludwig@9193
   179
    SDL_SCANCODE_UNKNOWN,       /* -- 138 */
dludwig@9193
   180
    SDL_SCANCODE_UNKNOWN,       /* -- 139 */
dludwig@9193
   181
    SDL_SCANCODE_UNKNOWN,       /* -- 140 */
dludwig@9193
   182
    SDL_SCANCODE_UNKNOWN,       /* -- 141 */
dludwig@9193
   183
    SDL_SCANCODE_UNKNOWN,       /* -- 142 */
dludwig@9193
   184
    SDL_SCANCODE_UNKNOWN,       /* -- 143 */
dludwig@9193
   185
    SDL_SCANCODE_NUMLOCKCLEAR,  /* VirtualKey.NumberKeyLock -- 144 */
dludwig@9193
   186
    SDL_SCANCODE_SCROLLLOCK,    /* VirtualKey.Scroll -- 145 */
dludwig@9193
   187
    SDL_SCANCODE_UNKNOWN,       /* -- 146 */
dludwig@9193
   188
    SDL_SCANCODE_UNKNOWN,       /* -- 147 */
dludwig@9193
   189
    SDL_SCANCODE_UNKNOWN,       /* -- 148 */
dludwig@9193
   190
    SDL_SCANCODE_UNKNOWN,       /* -- 149 */
dludwig@9193
   191
    SDL_SCANCODE_UNKNOWN,       /* -- 150 */
dludwig@9193
   192
    SDL_SCANCODE_UNKNOWN,       /* -- 151 */
dludwig@9193
   193
    SDL_SCANCODE_UNKNOWN,       /* -- 152 */
dludwig@9193
   194
    SDL_SCANCODE_UNKNOWN,       /* -- 153 */
dludwig@9193
   195
    SDL_SCANCODE_UNKNOWN,       /* -- 154 */
dludwig@9193
   196
    SDL_SCANCODE_UNKNOWN,       /* -- 155 */
dludwig@9193
   197
    SDL_SCANCODE_UNKNOWN,       /* -- 156 */
dludwig@9193
   198
    SDL_SCANCODE_UNKNOWN,       /* -- 157 */
dludwig@9193
   199
    SDL_SCANCODE_UNKNOWN,       /* -- 158 */
dludwig@9193
   200
    SDL_SCANCODE_UNKNOWN,       /* -- 159 */
dludwig@9193
   201
    SDL_SCANCODE_LSHIFT,        /* VirtualKey.LeftShift -- 160 */
dludwig@9193
   202
    SDL_SCANCODE_RSHIFT,        /* VirtualKey.RightShift -- 161 */
dludwig@9193
   203
    SDL_SCANCODE_LCTRL,         /* VirtualKey.LeftControl -- 162 */
dludwig@9193
   204
    SDL_SCANCODE_RCTRL,         /* VirtualKey.RightControl -- 163 */
dludwig@9193
   205
    SDL_SCANCODE_MENU,          /* VirtualKey.LeftMenu -- 164 */
dludwig@9193
   206
    SDL_SCANCODE_MENU,          /* VirtualKey.RightMenu -- 165 */
dludwig@9193
   207
    SDL_SCANCODE_AC_BACK,       /* VirtualKey.GoBack -- 166 : The go back key. */
dludwig@9193
   208
    SDL_SCANCODE_AC_FORWARD,    /* VirtualKey.GoForward -- 167 : The go forward key. */
dludwig@9193
   209
    SDL_SCANCODE_AC_REFRESH,    /* VirtualKey.Refresh -- 168 : The refresh key. */
dludwig@9193
   210
    SDL_SCANCODE_AC_STOP,       /* VirtualKey.Stop -- 169 : The stop key. */
dludwig@9193
   211
    SDL_SCANCODE_AC_SEARCH,     /* VirtualKey.Search -- 170 : The search key. */
dludwig@9193
   212
    SDL_SCANCODE_AC_BOOKMARKS,  /* VirtualKey.Favorites -- 171 : The favorites key. */
dludwig@9193
   213
    SDL_SCANCODE_AC_HOME        /* VirtualKey.GoHome -- 172 : The go home key. */
slouken@8582
   214
};
slouken@8582
   215
dludwig@9188
   216
/* Attempt to translate a keycode that isn't listed in WinRT's VirtualKey enum.
dludwig@9188
   217
 */
dludwig@9188
   218
static SDL_Scancode
dludwig@9188
   219
WINRT_TranslateUnofficialKeycode(int keycode)
dludwig@9188
   220
{
dludwig@9188
   221
    switch (keycode) {
dludwig@9193
   222
        case 173: return SDL_SCANCODE_MUTE;         /* VK_VOLUME_MUTE */
dludwig@9193
   223
        case 174: return SDL_SCANCODE_VOLUMEDOWN;   /* VK_VOLUME_DOWN */
dludwig@9193
   224
        case 175: return SDL_SCANCODE_VOLUMEUP;     /* VK_VOLUME_UP */
dludwig@9193
   225
        case 176: return SDL_SCANCODE_AUDIONEXT;    /* VK_MEDIA_NEXT_TRACK */
dludwig@9193
   226
        case 177: return SDL_SCANCODE_AUDIOPREV;    /* VK_MEDIA_PREV_TRACK */
dludwig@9193
   227
        // case 178: return ;                       /* VK_MEDIA_STOP */
dludwig@9193
   228
        case 179: return SDL_SCANCODE_AUDIOPLAY;    /* VK_MEDIA_PLAY_PAUSE */
dludwig@9193
   229
        case 180: return SDL_SCANCODE_MAIL;         /* VK_LAUNCH_MAIL */
dludwig@9193
   230
        case 181: return SDL_SCANCODE_MEDIASELECT;  /* VK_LAUNCH_MEDIA_SELECT */
dludwig@9193
   231
        // case 182: return ;                       /* VK_LAUNCH_APP1 */
dludwig@9193
   232
        case 183: return SDL_SCANCODE_CALCULATOR;   /* VK_LAUNCH_APP2 */
dludwig@9193
   233
        // case 184: return ;                       /* ... reserved ... */
dludwig@9193
   234
        // case 185: return ;                       /* ... reserved ... */
dludwig@9193
   235
        case 186: return SDL_SCANCODE_SEMICOLON;    /* VK_OEM_1, ';:' key on US standard keyboards */
dludwig@9193
   236
        case 187: return SDL_SCANCODE_EQUALS;       /* VK_OEM_PLUS */
dludwig@9193
   237
        case 188: return SDL_SCANCODE_COMMA;        /* VK_OEM_COMMA */
dludwig@9193
   238
        case 189: return SDL_SCANCODE_MINUS;        /* VK_OEM_MINUS */
dludwig@9193
   239
        case 190: return SDL_SCANCODE_PERIOD;       /* VK_OEM_PERIOD */
dludwig@9193
   240
        case 191: return SDL_SCANCODE_SLASH;        /* VK_OEM_2, '/?' key on US standard keyboards */
dludwig@9193
   241
        case 192: return SDL_SCANCODE_GRAVE;        /* VK_OEM_3, '`~' key on US standard keyboards */
dludwig@9188
   242
        // ?
dludwig@9193
   243
        // ... reserved or unassigned ...
dludwig@9188
   244
        // ?
dludwig@9193
   245
        case 219: return SDL_SCANCODE_LEFTBRACKET;  /* VK_OEM_4, '[{' key on US standard keyboards */
dludwig@9193
   246
        case 220: return SDL_SCANCODE_BACKSLASH;    /* VK_OEM_5, '\|' key on US standard keyboards */
dludwig@9193
   247
        case 221: return SDL_SCANCODE_RIGHTBRACKET; /* VK_OEM_6, ']}' key on US standard keyboards */
dludwig@9193
   248
        case 222: return SDL_SCANCODE_APOSTROPHE;   /* VK_OEM_7, 'single/double quote' on US standard keyboards */
dludwig@9188
   249
        default: break;
dludwig@9188
   250
    }
dludwig@9188
   251
    return SDL_SCANCODE_UNKNOWN;
dludwig@9188
   252
}
slouken@8582
   253
slouken@8582
   254
static SDL_Scancode
dludwig@9193
   255
WINRT_TranslateKeycode(int keycode, unsigned int nativeScancode)
slouken@8582
   256
{
dludwig@9189
   257
    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
dludwig@9193
   258
dludwig@9189
   259
    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
dludwig@9189
   260
dludwig@9189
   261
    /* HACK ALERT: At least one VirtualKey constant (Shift) with a left/right
dludwig@9189
   262
     * designation might not get reported with its correct handedness, however
dludwig@9189
   263
     * its hardware scan code can fill in the gaps.  If this is detected,
dludwig@9189
   264
     * use the hardware scan code to try telling if the left, or the right
dludwig@9189
   265
     * side's key was used.
dludwig@9189
   266
     *
dludwig@9189
   267
     * If Microsoft ever allows MapVirtualKey or MapVirtualKeyEx to be used
dludwig@9189
   268
     * in WinRT apps, or something similar to these (it doesn't appear to be,
dludwig@9189
   269
     * at least not for Windows [Phone] 8/8.1, as of Oct 24, 2014), then this
dludwig@9189
   270
     * hack might become deprecated, or obsolete.
dludwig@9189
   271
     */
dludwig@9190
   272
    if (nativeScancode < SDL_arraysize(windows_scancode_table)) {
dludwig@9189
   273
        switch (keycode) {
dludwig@9189
   274
            case 16:    // VirtualKey.Shift
dludwig@9189
   275
                switch (windows_scancode_table[nativeScancode]) {
dludwig@9189
   276
                    case SDL_SCANCODE_LSHIFT:
dludwig@9189
   277
                    case SDL_SCANCODE_RSHIFT:
dludwig@9189
   278
                        return windows_scancode_table[nativeScancode];
dludwig@9189
   279
                }
dludwig@9189
   280
                break;
dludwig@9189
   281
            
dludwig@9189
   282
            // Add others, as necessary.
dludwig@9189
   283
            //
dludwig@9189
   284
            // Unfortunately, this hack doesn't seem to work in determining
dludwig@9189
   285
            // handedness with Control keys.
dludwig@9189
   286
dludwig@9189
   287
            default:
dludwig@9189
   288
                break;
dludwig@9189
   289
        }
dludwig@9189
   290
    }
dludwig@9189
   291
dludwig@9189
   292
    /* Try to get a documented, WinRT, 'VirtualKey' next (as documented at
slouken@8582
   293
       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
slouken@8582
   294
       If that fails, fall back to a Win32 virtual key.
dludwig@9191
   295
       If that fails, attempt to fall back to a scancode-derived key.
slouken@8582
   296
    */
slouken@8582
   297
    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
slouken@8582
   298
        scancode = WinRT_Official_Keycodes[keycode];
slouken@8582
   299
    }
slouken@8582
   300
    if (scancode == SDL_SCANCODE_UNKNOWN) {
dludwig@9188
   301
        scancode = WINRT_TranslateUnofficialKeycode(keycode);
slouken@8582
   302
    }
slouken@8582
   303
    if (scancode == SDL_SCANCODE_UNKNOWN) {
dludwig@9191
   304
        if (nativeScancode < SDL_arraysize(windows_scancode_table)) {
dludwig@9191
   305
            scancode = windows_scancode_table[nativeScancode];
dludwig@9191
   306
        }
dludwig@9191
   307
    }
dludwig@9192
   308
    /*
dludwig@9191
   309
    if (scancode == SDL_SCANCODE_UNKNOWN) {
slouken@8582
   310
        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
slouken@8582
   311
    }
dludwig@9192
   312
    */
slouken@8582
   313
    return scancode;
slouken@8582
   314
}
slouken@8582
   315
slouken@8582
   316
void
slouken@8582
   317
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
slouken@8582
   318
{
dludwig@9193
   319
    SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
slouken@8582
   320
#if 0
slouken@8582
   321
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
dludwig@9190
   322
    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, "
dludwig@9190
   323
            "repeat count=%d, native scan code=0x%x, was down?=%s, vkey=%d, "
dludwig@9190
   324
            "sdl scan code=%d (%s), sdl key code=%d (%s)\n",
slouken@8582
   325
        (args->Handled ? "1" : "0"),
slouken@8582
   326
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
slouken@8582
   327
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
slouken@8582
   328
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
slouken@8582
   329
        args->KeyStatus.RepeatCount,
slouken@8582
   330
        args->KeyStatus.ScanCode,
slouken@8582
   331
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
slouken@8582
   332
        args->VirtualKey,
slouken@8582
   333
        sdlScancode,
slouken@8582
   334
        SDL_GetScancodeName(sdlScancode),
slouken@8582
   335
        keycode,
slouken@8582
   336
        SDL_GetKeyName(keycode));
slouken@8582
   337
    //args->Handled = true;
slouken@8582
   338
#endif
slouken@8582
   339
    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
slouken@8582
   340
}
slouken@8582
   341
slouken@8582
   342
void
slouken@8582
   343
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
slouken@8582
   344
{
dludwig@9193
   345
    SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
slouken@8582
   346
#if 0
slouken@8582
   347
    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
dludwig@9190
   348
    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, "
dludwig@9190
   349
            "repeat count=%d, native scan code=0x%x, was down?=%s, vkey=%d, "
dludwig@9190
   350
            "sdl scan code=%d (%s), sdl key code=%d (%s)\n",
slouken@8582
   351
        (args->Handled ? "1" : "0"),
slouken@8582
   352
        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
slouken@8582
   353
        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
slouken@8582
   354
        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
slouken@8582
   355
        args->KeyStatus.RepeatCount,
slouken@8582
   356
        args->KeyStatus.ScanCode,
slouken@8582
   357
        (args->KeyStatus.WasKeyDown ? "1" : "0"),
slouken@8582
   358
        args->VirtualKey,
slouken@8582
   359
        sdlScancode,
slouken@8582
   360
        SDL_GetScancodeName(sdlScancode),
slouken@8582
   361
        keycode,
slouken@8582
   362
        SDL_GetKeyName(keycode));
slouken@8582
   363
    //args->Handled = true;
slouken@8582
   364
#endif
slouken@8582
   365
    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
slouken@8582
   366
}
slouken@8582
   367
dludwig@9240
   368
void
dludwig@9240
   369
WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args)
dludwig@9240
   370
{
dludwig@9240
   371
    wchar_t src_ucs2[2];
dludwig@9240
   372
    char dest_utf8[16];
dludwig@9240
   373
    int result;
dludwig@9240
   374
dludwig@9240
   375
    /* Setup src */
dludwig@9240
   376
    src_ucs2[0] = args->KeyCode;
dludwig@9240
   377
    src_ucs2[1] = L'\0';
dludwig@9240
   378
dludwig@9240
   379
    /* Convert the text, then send an SDL_TEXTINPUT event. */
dludwig@9240
   380
    result = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&src_ucs2, -1, (LPSTR)dest_utf8, sizeof(dest_utf8), NULL, NULL);
dludwig@9240
   381
    if (result > 0) {
dludwig@9240
   382
        SDL_SendKeyboardText(dest_utf8);
dludwig@9240
   383
    }
dludwig@9240
   384
}
dludwig@9240
   385
slouken@8582
   386
#endif // SDL_VIDEO_DRIVER_WINRT