src/events/SDL_keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 22 Jun 2015 23:36:06 -0700
changeset 9776 952ff8a5076f
parent 9678 9e8323b058d6
child 9973 4d8a561cf978
permissions -rw-r--r--
Fixed bug 3030 - SDL_RecreateWindow fails to restore title, icon, etc.

Adam M.

It loses the title and icon when window recreation fails. For instance, this may happen when trying to create an OpenGL ES window on a system that doesn't support it. But at that point, the title and icon have already been lost.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@0
    22
slouken@0
    23
/* General keyboard handling code for SDL */
slouken@0
    24
slouken@1358
    25
#include "SDL_timer.h"
slouken@0
    26
#include "SDL_events.h"
slouken@0
    27
#include "SDL_events_c.h"
icculus@8927
    28
#include "SDL_assert.h"
slouken@5123
    29
#include "../video/SDL_sysvideo.h"
slouken@0
    30
slouken@0
    31
gabomdq@7678
    32
/* #define DEBUG_KEYBOARD */
slouken@6661
    33
slouken@1895
    34
/* Global keyboard information */
slouken@4465
    35
slouken@4465
    36
typedef struct SDL_Keyboard SDL_Keyboard;
slouken@4465
    37
slouken@4465
    38
struct SDL_Keyboard
slouken@4465
    39
{
slouken@4465
    40
    /* Data common to all keyboards */
slouken@4465
    41
    SDL_Window *focus;
slouken@4465
    42
    Uint16 modstate;
slouken@4465
    43
    Uint8 keystate[SDL_NUM_SCANCODES];
slouken@5220
    44
    SDL_Keycode keymap[SDL_NUM_SCANCODES];
slouken@4465
    45
};
slouken@4465
    46
slouken@4465
    47
static SDL_Keyboard SDL_keyboard;
slouken@0
    48
slouken@5220
    49
static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES] = {
slouken@2303
    50
    0, 0, 0, 0,
slouken@2303
    51
    'a',
slouken@2303
    52
    'b',
slouken@2303
    53
    'c',
slouken@2303
    54
    'd',
slouken@2303
    55
    'e',
slouken@2303
    56
    'f',
slouken@2303
    57
    'g',
slouken@2303
    58
    'h',
slouken@2303
    59
    'i',
slouken@2303
    60
    'j',
slouken@2303
    61
    'k',
slouken@2303
    62
    'l',
slouken@2303
    63
    'm',
slouken@2303
    64
    'n',
slouken@2303
    65
    'o',
slouken@2303
    66
    'p',
slouken@2303
    67
    'q',
slouken@2303
    68
    'r',
slouken@2303
    69
    's',
slouken@2303
    70
    't',
slouken@2303
    71
    'u',
slouken@2303
    72
    'v',
slouken@2303
    73
    'w',
slouken@2303
    74
    'x',
slouken@2303
    75
    'y',
slouken@2303
    76
    'z',
slouken@2303
    77
    '1',
slouken@2303
    78
    '2',
slouken@2303
    79
    '3',
slouken@2303
    80
    '4',
slouken@2303
    81
    '5',
slouken@2303
    82
    '6',
slouken@2303
    83
    '7',
slouken@2303
    84
    '8',
slouken@2303
    85
    '9',
slouken@2303
    86
    '0',
slouken@2303
    87
    SDLK_RETURN,
slouken@2303
    88
    SDLK_ESCAPE,
slouken@2303
    89
    SDLK_BACKSPACE,
slouken@2303
    90
    SDLK_TAB,
slouken@2303
    91
    SDLK_SPACE,
slouken@2303
    92
    '-',
slouken@2303
    93
    '=',
slouken@2303
    94
    '[',
slouken@2303
    95
    ']',
slouken@2303
    96
    '\\',
slouken@2303
    97
    '#',
slouken@2303
    98
    ';',
slouken@2303
    99
    '\'',
slouken@2303
   100
    '`',
slouken@2303
   101
    ',',
slouken@2303
   102
    '.',
slouken@2303
   103
    '/',
slouken@2303
   104
    SDLK_CAPSLOCK,
slouken@2303
   105
    SDLK_F1,
slouken@2303
   106
    SDLK_F2,
slouken@2303
   107
    SDLK_F3,
slouken@2303
   108
    SDLK_F4,
slouken@2303
   109
    SDLK_F5,
slouken@2303
   110
    SDLK_F6,
slouken@2303
   111
    SDLK_F7,
slouken@2303
   112
    SDLK_F8,
slouken@2303
   113
    SDLK_F9,
slouken@2303
   114
    SDLK_F10,
slouken@2303
   115
    SDLK_F11,
slouken@2303
   116
    SDLK_F12,
slouken@2303
   117
    SDLK_PRINTSCREEN,
slouken@2303
   118
    SDLK_SCROLLLOCK,
slouken@2303
   119
    SDLK_PAUSE,
slouken@2303
   120
    SDLK_INSERT,
slouken@2303
   121
    SDLK_HOME,
slouken@2303
   122
    SDLK_PAGEUP,
slouken@2303
   123
    SDLK_DELETE,
slouken@2303
   124
    SDLK_END,
slouken@2303
   125
    SDLK_PAGEDOWN,
slouken@2303
   126
    SDLK_RIGHT,
slouken@2303
   127
    SDLK_LEFT,
slouken@2303
   128
    SDLK_DOWN,
slouken@2303
   129
    SDLK_UP,
slouken@2303
   130
    SDLK_NUMLOCKCLEAR,
slouken@2303
   131
    SDLK_KP_DIVIDE,
slouken@2303
   132
    SDLK_KP_MULTIPLY,
slouken@2303
   133
    SDLK_KP_MINUS,
slouken@2303
   134
    SDLK_KP_PLUS,
slouken@2303
   135
    SDLK_KP_ENTER,
slouken@2303
   136
    SDLK_KP_1,
slouken@2303
   137
    SDLK_KP_2,
slouken@2303
   138
    SDLK_KP_3,
slouken@2303
   139
    SDLK_KP_4,
slouken@2303
   140
    SDLK_KP_5,
slouken@2303
   141
    SDLK_KP_6,
slouken@2303
   142
    SDLK_KP_7,
slouken@2303
   143
    SDLK_KP_8,
slouken@2303
   144
    SDLK_KP_9,
slouken@2303
   145
    SDLK_KP_0,
slouken@2303
   146
    SDLK_KP_PERIOD,
slouken@2303
   147
    0,
slouken@2303
   148
    SDLK_APPLICATION,
slouken@2303
   149
    SDLK_POWER,
slouken@2303
   150
    SDLK_KP_EQUALS,
slouken@2303
   151
    SDLK_F13,
slouken@2303
   152
    SDLK_F14,
slouken@2303
   153
    SDLK_F15,
slouken@2303
   154
    SDLK_F16,
slouken@2303
   155
    SDLK_F17,
slouken@2303
   156
    SDLK_F18,
slouken@2303
   157
    SDLK_F19,
slouken@2303
   158
    SDLK_F20,
slouken@2303
   159
    SDLK_F21,
slouken@2303
   160
    SDLK_F22,
slouken@2303
   161
    SDLK_F23,
slouken@2303
   162
    SDLK_F24,
slouken@2303
   163
    SDLK_EXECUTE,
slouken@2303
   164
    SDLK_HELP,
slouken@2303
   165
    SDLK_MENU,
slouken@2303
   166
    SDLK_SELECT,
slouken@2303
   167
    SDLK_STOP,
slouken@2303
   168
    SDLK_AGAIN,
slouken@2303
   169
    SDLK_UNDO,
slouken@2303
   170
    SDLK_CUT,
slouken@2303
   171
    SDLK_COPY,
slouken@2303
   172
    SDLK_PASTE,
slouken@2303
   173
    SDLK_FIND,
slouken@2303
   174
    SDLK_MUTE,
slouken@2303
   175
    SDLK_VOLUMEUP,
slouken@2303
   176
    SDLK_VOLUMEDOWN,
slouken@2303
   177
    0, 0, 0,
slouken@2303
   178
    SDLK_KP_COMMA,
slouken@2303
   179
    SDLK_KP_EQUALSAS400,
slouken@2303
   180
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
slouken@2303
   181
    SDLK_ALTERASE,
slouken@2303
   182
    SDLK_SYSREQ,
slouken@2303
   183
    SDLK_CANCEL,
slouken@2303
   184
    SDLK_CLEAR,
slouken@2303
   185
    SDLK_PRIOR,
slouken@2303
   186
    SDLK_RETURN2,
slouken@2303
   187
    SDLK_SEPARATOR,
slouken@2303
   188
    SDLK_OUT,
slouken@2303
   189
    SDLK_OPER,
slouken@2303
   190
    SDLK_CLEARAGAIN,
slouken@2303
   191
    SDLK_CRSEL,
slouken@2303
   192
    SDLK_EXSEL,
slouken@2303
   193
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
slouken@2303
   194
    SDLK_KP_00,
slouken@2303
   195
    SDLK_KP_000,
slouken@2303
   196
    SDLK_THOUSANDSSEPARATOR,
slouken@2303
   197
    SDLK_DECIMALSEPARATOR,
slouken@2303
   198
    SDLK_CURRENCYUNIT,
slouken@2303
   199
    SDLK_CURRENCYSUBUNIT,
slouken@2303
   200
    SDLK_KP_LEFTPAREN,
slouken@2303
   201
    SDLK_KP_RIGHTPAREN,
slouken@2303
   202
    SDLK_KP_LEFTBRACE,
slouken@2303
   203
    SDLK_KP_RIGHTBRACE,
slouken@2303
   204
    SDLK_KP_TAB,
slouken@2303
   205
    SDLK_KP_BACKSPACE,
slouken@2303
   206
    SDLK_KP_A,
slouken@2303
   207
    SDLK_KP_B,
slouken@2303
   208
    SDLK_KP_C,
slouken@2303
   209
    SDLK_KP_D,
slouken@2303
   210
    SDLK_KP_E,
slouken@2303
   211
    SDLK_KP_F,
slouken@2303
   212
    SDLK_KP_XOR,
slouken@2303
   213
    SDLK_KP_POWER,
slouken@2303
   214
    SDLK_KP_PERCENT,
slouken@2303
   215
    SDLK_KP_LESS,
slouken@2303
   216
    SDLK_KP_GREATER,
slouken@2303
   217
    SDLK_KP_AMPERSAND,
slouken@2303
   218
    SDLK_KP_DBLAMPERSAND,
slouken@2303
   219
    SDLK_KP_VERTICALBAR,
slouken@2303
   220
    SDLK_KP_DBLVERTICALBAR,
slouken@2303
   221
    SDLK_KP_COLON,
slouken@2303
   222
    SDLK_KP_HASH,
slouken@2303
   223
    SDLK_KP_SPACE,
slouken@2303
   224
    SDLK_KP_AT,
slouken@2303
   225
    SDLK_KP_EXCLAM,
slouken@2303
   226
    SDLK_KP_MEMSTORE,
slouken@2303
   227
    SDLK_KP_MEMRECALL,
slouken@2303
   228
    SDLK_KP_MEMCLEAR,
slouken@2303
   229
    SDLK_KP_MEMADD,
slouken@2303
   230
    SDLK_KP_MEMSUBTRACT,
slouken@2303
   231
    SDLK_KP_MEMMULTIPLY,
slouken@2303
   232
    SDLK_KP_MEMDIVIDE,
slouken@2303
   233
    SDLK_KP_PLUSMINUS,
slouken@2303
   234
    SDLK_KP_CLEAR,
slouken@2303
   235
    SDLK_KP_CLEARENTRY,
slouken@2303
   236
    SDLK_KP_BINARY,
slouken@2303
   237
    SDLK_KP_OCTAL,
slouken@2303
   238
    SDLK_KP_DECIMAL,
slouken@2303
   239
    SDLK_KP_HEXADECIMAL,
slouken@2303
   240
    0, 0,
slouken@2303
   241
    SDLK_LCTRL,
slouken@2303
   242
    SDLK_LSHIFT,
slouken@2303
   243
    SDLK_LALT,
slouken@2303
   244
    SDLK_LGUI,
slouken@2303
   245
    SDLK_RCTRL,
slouken@2303
   246
    SDLK_RSHIFT,
slouken@2303
   247
    SDLK_RALT,
slouken@2303
   248
    SDLK_RGUI,
slouken@2303
   249
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
slouken@2303
   250
    SDLK_MODE,
slouken@2303
   251
    SDLK_AUDIONEXT,
slouken@2303
   252
    SDLK_AUDIOPREV,
slouken@2303
   253
    SDLK_AUDIOSTOP,
slouken@2303
   254
    SDLK_AUDIOPLAY,
slouken@2303
   255
    SDLK_AUDIOMUTE,
slouken@2303
   256
    SDLK_MEDIASELECT,
slouken@2305
   257
    SDLK_WWW,
slouken@2303
   258
    SDLK_MAIL,
slouken@2303
   259
    SDLK_CALCULATOR,
slouken@2303
   260
    SDLK_COMPUTER,
slouken@2303
   261
    SDLK_AC_SEARCH,
slouken@2303
   262
    SDLK_AC_HOME,
slouken@2303
   263
    SDLK_AC_BACK,
slouken@2303
   264
    SDLK_AC_FORWARD,
slouken@2303
   265
    SDLK_AC_STOP,
slouken@2303
   266
    SDLK_AC_REFRESH,
slouken@2303
   267
    SDLK_AC_BOOKMARKS,
slouken@2303
   268
    SDLK_BRIGHTNESSDOWN,
slouken@2303
   269
    SDLK_BRIGHTNESSUP,
slouken@2303
   270
    SDLK_DISPLAYSWITCH,
slouken@2303
   271
    SDLK_KBDILLUMTOGGLE,
slouken@2303
   272
    SDLK_KBDILLUMDOWN,
slouken@2303
   273
    SDLK_KBDILLUMUP,
slouken@2303
   274
    SDLK_EJECT,
slouken@2303
   275
    SDLK_SLEEP,
slouken@2303
   276
};
slouken@2303
   277
slouken@2303
   278
static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
slouken@2303
   279
    NULL, NULL, NULL, NULL,
slouken@2303
   280
    "A",
slouken@2303
   281
    "B",
slouken@2303
   282
    "C",
slouken@2303
   283
    "D",
slouken@2303
   284
    "E",
slouken@2303
   285
    "F",
slouken@2303
   286
    "G",
slouken@2303
   287
    "H",
slouken@2303
   288
    "I",
slouken@2303
   289
    "J",
slouken@2303
   290
    "K",
slouken@2303
   291
    "L",
slouken@2303
   292
    "M",
slouken@2303
   293
    "N",
slouken@2303
   294
    "O",
slouken@2303
   295
    "P",
slouken@2303
   296
    "Q",
slouken@2303
   297
    "R",
slouken@2303
   298
    "S",
slouken@2303
   299
    "T",
slouken@2303
   300
    "U",
slouken@2303
   301
    "V",
slouken@2303
   302
    "W",
slouken@2303
   303
    "X",
slouken@2303
   304
    "Y",
slouken@2303
   305
    "Z",
slouken@2303
   306
    "1",
slouken@2303
   307
    "2",
slouken@2303
   308
    "3",
slouken@2303
   309
    "4",
slouken@2303
   310
    "5",
slouken@2303
   311
    "6",
slouken@2303
   312
    "7",
slouken@2303
   313
    "8",
slouken@2303
   314
    "9",
slouken@2303
   315
    "0",
slouken@2303
   316
    "Return",
slouken@2303
   317
    "Escape",
slouken@2303
   318
    "Backspace",
slouken@2303
   319
    "Tab",
slouken@2303
   320
    "Space",
slouken@2303
   321
    "-",
slouken@2303
   322
    "=",
slouken@2303
   323
    "[",
slouken@2303
   324
    "]",
slouken@2303
   325
    "\\",
slouken@2303
   326
    "#",
slouken@2303
   327
    ";",
slouken@2303
   328
    "'",
slouken@2303
   329
    "`",
slouken@2303
   330
    ",",
slouken@2303
   331
    ".",
slouken@2303
   332
    "/",
slouken@2303
   333
    "CapsLock",
slouken@2303
   334
    "F1",
slouken@2303
   335
    "F2",
slouken@2303
   336
    "F3",
slouken@2303
   337
    "F4",
slouken@2303
   338
    "F5",
slouken@2303
   339
    "F6",
slouken@2303
   340
    "F7",
slouken@2303
   341
    "F8",
slouken@2303
   342
    "F9",
slouken@2303
   343
    "F10",
slouken@2303
   344
    "F11",
slouken@2303
   345
    "F12",
slouken@2303
   346
    "PrintScreen",
slouken@2303
   347
    "ScrollLock",
slouken@2303
   348
    "Pause",
slouken@2303
   349
    "Insert",
slouken@2303
   350
    "Home",
slouken@2303
   351
    "PageUp",
slouken@2303
   352
    "Delete",
slouken@2303
   353
    "End",
slouken@2303
   354
    "PageDown",
slouken@2303
   355
    "Right",
slouken@2303
   356
    "Left",
slouken@2303
   357
    "Down",
slouken@2303
   358
    "Up",
slouken@2303
   359
    "Numlock",
slouken@2303
   360
    "Keypad /",
slouken@2303
   361
    "Keypad *",
slouken@2303
   362
    "Keypad -",
slouken@2303
   363
    "Keypad +",
slouken@2303
   364
    "Keypad Enter",
slouken@2303
   365
    "Keypad 1",
slouken@2303
   366
    "Keypad 2",
slouken@2303
   367
    "Keypad 3",
slouken@2303
   368
    "Keypad 4",
slouken@2303
   369
    "Keypad 5",
slouken@2303
   370
    "Keypad 6",
slouken@2303
   371
    "Keypad 7",
slouken@2303
   372
    "Keypad 8",
slouken@2303
   373
    "Keypad 9",
slouken@2303
   374
    "Keypad 0",
slouken@2303
   375
    "Keypad .",
slouken@2303
   376
    NULL,
slouken@2303
   377
    "Application",
slouken@2303
   378
    "Power",
slouken@2303
   379
    "Keypad =",
slouken@2303
   380
    "F13",
slouken@2303
   381
    "F14",
slouken@2303
   382
    "F15",
slouken@2303
   383
    "F16",
slouken@2303
   384
    "F17",
slouken@2303
   385
    "F18",
slouken@2303
   386
    "F19",
slouken@2303
   387
    "F20",
slouken@2303
   388
    "F21",
slouken@2303
   389
    "F22",
slouken@2303
   390
    "F23",
slouken@2303
   391
    "F24",
slouken@2303
   392
    "Execute",
slouken@2303
   393
    "Help",
slouken@2303
   394
    "Menu",
slouken@2303
   395
    "Select",
slouken@2303
   396
    "Stop",
slouken@2303
   397
    "Again",
slouken@2303
   398
    "Undo",
slouken@2303
   399
    "Cut",
slouken@2303
   400
    "Copy",
slouken@2303
   401
    "Paste",
slouken@2303
   402
    "Find",
slouken@2303
   403
    "Mute",
slouken@2303
   404
    "VolumeUp",
slouken@2303
   405
    "VolumeDown",
slouken@2303
   406
    NULL, NULL, NULL,
slouken@2303
   407
    "Keypad ,",
slouken@2303
   408
    "Keypad = (AS400)",
slouken@2303
   409
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
slouken@2303
   410
    NULL, NULL, NULL, NULL, NULL, NULL,
slouken@2303
   411
    "AltErase",
slouken@2303
   412
    "SysReq",
slouken@2303
   413
    "Cancel",
slouken@2303
   414
    "Clear",
slouken@2303
   415
    "Prior",
slouken@2303
   416
    "Return",
slouken@2303
   417
    "Separator",
slouken@2303
   418
    "Out",
slouken@2303
   419
    "Oper",
slouken@2303
   420
    "Clear / Again",
slouken@2303
   421
    "CrSel",
slouken@2303
   422
    "ExSel",
slouken@2303
   423
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
slouken@2303
   424
    "Keypad 00",
slouken@2303
   425
    "Keypad 000",
slouken@2303
   426
    "ThousandsSeparator",
slouken@2303
   427
    "DecimalSeparator",
slouken@2303
   428
    "CurrencyUnit",
slouken@2303
   429
    "CurrencySubUnit",
slouken@2303
   430
    "Keypad (",
slouken@2303
   431
    "Keypad )",
slouken@2303
   432
    "Keypad {",
slouken@2303
   433
    "Keypad }",
slouken@2303
   434
    "Keypad Tab",
slouken@2303
   435
    "Keypad Backspace",
slouken@2303
   436
    "Keypad A",
slouken@2303
   437
    "Keypad B",
slouken@2303
   438
    "Keypad C",
slouken@2303
   439
    "Keypad D",
slouken@2303
   440
    "Keypad E",
slouken@2303
   441
    "Keypad F",
slouken@2303
   442
    "Keypad XOR",
slouken@2303
   443
    "Keypad ^",
slouken@2303
   444
    "Keypad %",
slouken@2303
   445
    "Keypad <",
slouken@2303
   446
    "Keypad >",
slouken@2303
   447
    "Keypad &",
slouken@2303
   448
    "Keypad &&",
slouken@2303
   449
    "Keypad |",
slouken@2303
   450
    "Keypad ||",
slouken@2303
   451
    "Keypad :",
slouken@2303
   452
    "Keypad #",
slouken@2303
   453
    "Keypad Space",
slouken@2303
   454
    "Keypad @",
slouken@2303
   455
    "Keypad !",
slouken@2303
   456
    "Keypad MemStore",
slouken@2303
   457
    "Keypad MemRecall",
slouken@2303
   458
    "Keypad MemClear",
slouken@2303
   459
    "Keypad MemAdd",
slouken@2303
   460
    "Keypad MemSubtract",
slouken@2303
   461
    "Keypad MemMultiply",
slouken@2303
   462
    "Keypad MemDivide",
slouken@2303
   463
    "Keypad +/-",
slouken@2303
   464
    "Keypad Clear",
slouken@2303
   465
    "Keypad ClearEntry",
slouken@2303
   466
    "Keypad Binary",
slouken@2303
   467
    "Keypad Octal",
slouken@2303
   468
    "Keypad Decimal",
slouken@2303
   469
    "Keypad Hexadecimal",
slouken@2303
   470
    NULL, NULL,
slouken@2303
   471
    "Left Ctrl",
slouken@2303
   472
    "Left Shift",
slouken@2303
   473
    "Left Alt",
slouken@2303
   474
    "Left GUI",
slouken@2303
   475
    "Right Ctrl",
slouken@2303
   476
    "Right Shift",
slouken@2303
   477
    "Right Alt",
slouken@2303
   478
    "Right GUI",
slouken@2303
   479
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
slouken@2303
   480
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
slouken@2303
   481
    NULL,
slouken@2303
   482
    "ModeSwitch",
slouken@2303
   483
    "AudioNext",
slouken@2303
   484
    "AudioPrev",
slouken@2303
   485
    "AudioStop",
slouken@2303
   486
    "AudioPlay",
slouken@2303
   487
    "AudioMute",
slouken@2303
   488
    "MediaSelect",
slouken@2305
   489
    "WWW",
slouken@2303
   490
    "Mail",
slouken@2303
   491
    "Calculator",
slouken@2303
   492
    "Computer",
slouken@2303
   493
    "AC Search",
slouken@2303
   494
    "AC Home",
slouken@2303
   495
    "AC Back",
slouken@2303
   496
    "AC Forward",
slouken@2303
   497
    "AC Stop",
slouken@2303
   498
    "AC Refresh",
slouken@2303
   499
    "AC Bookmarks",
slouken@2303
   500
    "BrightnessDown",
slouken@2303
   501
    "BrightnessUp",
slouken@2303
   502
    "DisplaySwitch",
slouken@2303
   503
    "KBDIllumToggle",
slouken@2303
   504
    "KBDIllumDown",
slouken@2303
   505
    "KBDIllumUp",
slouken@2303
   506
    "Eject",
slouken@2303
   507
    "Sleep",
slouken@2303
   508
};
slouken@2303
   509
bob@2295
   510
/* Taken from SDL_iconv() */
gabomdq@7778
   511
char *
slouken@2303
   512
SDL_UCS4ToUTF8(Uint32 ch, char *dst)
bob@2295
   513
{
bob@2295
   514
    Uint8 *p = (Uint8 *) dst;
bob@2295
   515
    if (ch <= 0x7F) {
bob@2295
   516
        *p = (Uint8) ch;
bob@2295
   517
        ++dst;
bob@2295
   518
    } else if (ch <= 0x7FF) {
bob@2295
   519
        p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
bob@2295
   520
        p[1] = 0x80 | (Uint8) (ch & 0x3F);
bob@2295
   521
        dst += 2;
bob@2295
   522
    } else if (ch <= 0xFFFF) {
bob@2295
   523
        p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
bob@2295
   524
        p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
bob@2295
   525
        p[2] = 0x80 | (Uint8) (ch & 0x3F);
bob@2295
   526
        dst += 3;
bob@2295
   527
    } else if (ch <= 0x1FFFFF) {
bob@2295
   528
        p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
bob@2295
   529
        p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
bob@2295
   530
        p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
bob@2295
   531
        p[3] = 0x80 | (Uint8) (ch & 0x3F);
bob@2295
   532
        dst += 4;
bob@2295
   533
    } else if (ch <= 0x3FFFFFF) {
bob@2295
   534
        p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
bob@2295
   535
        p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
bob@2295
   536
        p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
bob@2295
   537
        p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
bob@2295
   538
        p[4] = 0x80 | (Uint8) (ch & 0x3F);
bob@2295
   539
        dst += 5;
bob@2295
   540
    } else {
bob@2295
   541
        p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
bob@2295
   542
        p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
bob@2295
   543
        p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
bob@2295
   544
        p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
bob@2295
   545
        p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
bob@2295
   546
        p[5] = 0x80 | (Uint8) (ch & 0x3F);
bob@2295
   547
        dst += 6;
bob@2295
   548
    }
bob@2295
   549
    return dst;
bob@2295
   550
}
bob@2295
   551
slouken@0
   552
/* Public functions */
slouken@1895
   553
int
slouken@1895
   554
SDL_KeyboardInit(void)
slouken@0
   555
{
slouken@4490
   556
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@4490
   557
slouken@4490
   558
    /* Set the default keymap */
slouken@4490
   559
    SDL_memcpy(keyboard->keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
slouken@1895
   560
    return (0);
slouken@1895
   561
}
slouken@1895
   562
slouken@4465
   563
void
slouken@4465
   564
SDL_ResetKeyboard(void)
slouken@1895
   565
{
slouken@4465
   566
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@5218
   567
    SDL_Scancode scancode;
slouken@0
   568
slouken@6661
   569
#ifdef DEBUG_KEYBOARD
slouken@6661
   570
    printf("Resetting keyboard\n");
slouken@6661
   571
#endif
slouken@2303
   572
    for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
slouken@2303
   573
        if (keyboard->keystate[scancode] == SDL_PRESSED) {
slouken@4465
   574
            SDL_SendKeyboardKey(SDL_RELEASED, scancode);
slouken@1895
   575
        }
slouken@1895
   576
    }
slouken@1123
   577
}
slouken@0
   578
slouken@1895
   579
void
slouken@5220
   580
SDL_GetDefaultKeymap(SDL_Keycode * keymap)
slouken@0
   581
{
slouken@2303
   582
    SDL_memcpy(keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
slouken@0
   583
}
slouken@0
   584
slouken@1895
   585
void
slouken@5220
   586
SDL_SetKeymap(int start, SDL_Keycode * keys, int length)
slouken@0
   587
{
slouken@4465
   588
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@1895
   589
slouken@2303
   590
    if (start < 0 || start + length > SDL_NUM_SCANCODES) {
slouken@2303
   591
        return;
slouken@1895
   592
    }
slouken@2268
   593
slouken@2303
   594
    SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
slouken@0
   595
}
slouken@0
   596
slouken@1895
   597
void
slouken@5218
   598
SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
slouken@2268
   599
{
slouken@2303
   600
    SDL_scancode_names[scancode] = name;
slouken@2268
   601
}
slouken@2268
   602
slouken@4465
   603
SDL_Window *
slouken@4465
   604
SDL_GetKeyboardFocus(void)
slouken@0
   605
{
slouken@4465
   606
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@4465
   607
slouken@4465
   608
    return keyboard->focus;
slouken@4465
   609
}
slouken@1895
   610
slouken@4465
   611
void
slouken@4465
   612
SDL_SetKeyboardFocus(SDL_Window * window)
slouken@4465
   613
{
slouken@4465
   614
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@0
   615
slouken@6665
   616
    if (keyboard->focus && !window) {
slouken@6665
   617
        /* We won't get anymore keyboard messages, so reset keyboard state */
slouken@6665
   618
        SDL_ResetKeyboard();
slouken@6665
   619
    }
slouken@6665
   620
slouken@1895
   621
    /* See if the current window has lost focus */
slouken@3685
   622
    if (keyboard->focus && keyboard->focus != window) {
icculus@8927
   623
icculus@8927
   624
        /* new window shouldn't think it has mouse captured. */
icculus@8927
   625
        SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
icculus@8927
   626
icculus@8927
   627
        /* old window must lose an existing mouse capture. */
icculus@8927
   628
        if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
icculus@8927
   629
            SDL_CaptureMouse(SDL_FALSE);  /* drop the capture. */
icculus@8927
   630
            SDL_assert(!(keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE));
icculus@8927
   631
        }
icculus@8927
   632
slouken@4465
   633
        SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
slouken@4465
   634
                            0, 0);
slouken@4890
   635
slouken@4890
   636
        /* Ensures IME compositions are committed */
slouken@4890
   637
        if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@4890
   638
            SDL_VideoDevice *video = SDL_GetVideoDevice();
slouken@4890
   639
            if (video && video->StopTextInput) {
slouken@4890
   640
                video->StopTextInput(video);
slouken@4890
   641
            }
slouken@4890
   642
        }
slouken@1895
   643
    }
slouken@1895
   644
slouken@3685
   645
    keyboard->focus = window;
slouken@1895
   646
slouken@1895
   647
    if (keyboard->focus) {
slouken@3502
   648
        SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
slouken@3502
   649
                            0, 0);
slouken@4435
   650
slouken@4435
   651
        if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
slouken@4890
   652
            SDL_VideoDevice *video = SDL_GetVideoDevice();
slouken@4890
   653
            if (video && video->StartTextInput) {
slouken@4890
   654
                video->StartTextInput(video);
slouken@4890
   655
            }
slouken@4435
   656
        }
slouken@1895
   657
    }
slouken@0
   658
}
slouken@0
   659
slouken@1895
   660
int
slouken@5218
   661
SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
slouken@0
   662
{
slouken@4465
   663
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@2129
   664
    int posted;
slouken@9678
   665
    SDL_Keymod modifier;
slouken@9678
   666
    SDL_Keycode keycode;
slouken@1895
   667
    Uint16 modstate;
slouken@4429
   668
    Uint32 type;
slouken@4565
   669
    Uint8 repeat;
slouken@0
   670
slouken@4465
   671
    if (!scancode) {
slouken@1895
   672
        return 0;
slouken@1895
   673
    }
slouken@6661
   674
#ifdef DEBUG_KEYBOARD
slouken@2303
   675
    printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
slouken@1895
   676
           state == SDL_PRESSED ? "pressed" : "released");
slouken@1895
   677
#endif
slouken@0
   678
slouken@1895
   679
    /* Figure out what type of event this is */
slouken@1895
   680
    switch (state) {
slouken@1895
   681
    case SDL_PRESSED:
slouken@1895
   682
        type = SDL_KEYDOWN;
slouken@1895
   683
        break;
slouken@1895
   684
    case SDL_RELEASED:
slouken@1895
   685
        type = SDL_KEYUP;
slouken@1895
   686
        break;
slouken@1895
   687
    default:
slouken@1895
   688
        /* Invalid state -- bail */
slouken@1895
   689
        return 0;
slouken@1895
   690
    }
slouken@0
   691
slouken@2303
   692
    /* Drop events that don't change state */
slouken@4565
   693
    repeat = (state && keyboard->keystate[scancode]);
slouken@4560
   694
    if (keyboard->keystate[scancode] == state && !repeat) {
slouken@1282
   695
#if 0
slouken@2303
   696
        printf("Keyboard event didn't change state - dropped!\n");
slouken@1282
   697
#endif
slouken@2303
   698
        return 0;
slouken@2303
   699
    }
slouken@0
   700
slouken@2303
   701
    /* Update internal keyboard state */
slouken@2303
   702
    keyboard->keystate[scancode] = state;
slouken@0
   703
slouken@9678
   704
    keycode = keyboard->keymap[scancode];
slouken@9678
   705
slouken@9678
   706
    /* Update modifiers state if applicable */
slouken@9678
   707
    switch (keycode) {
slouken@9678
   708
    case SDLK_LCTRL:
slouken@9678
   709
        modifier = KMOD_LCTRL;
slouken@9678
   710
        break;
slouken@9678
   711
    case SDLK_RCTRL:
slouken@9678
   712
        modifier = KMOD_RCTRL;
slouken@9678
   713
        break;
slouken@9678
   714
    case SDLK_LSHIFT:
slouken@9678
   715
        modifier = KMOD_LSHIFT;
slouken@9678
   716
        break;
slouken@9678
   717
    case SDLK_RSHIFT:
slouken@9678
   718
        modifier = KMOD_RSHIFT;
slouken@9678
   719
        break;
slouken@9678
   720
    case SDLK_LALT:
slouken@9678
   721
        modifier = KMOD_LALT;
slouken@9678
   722
        break;
slouken@9678
   723
    case SDLK_RALT:
slouken@9678
   724
        modifier = KMOD_RALT;
slouken@9678
   725
        break;
slouken@9678
   726
    case SDLK_LGUI:
slouken@9678
   727
        modifier = KMOD_LGUI;
slouken@9678
   728
        break;
slouken@9678
   729
    case SDLK_RGUI:
slouken@9678
   730
        modifier = KMOD_RGUI;
slouken@9678
   731
        break;
slouken@9678
   732
    case SDLK_MODE:
slouken@9678
   733
        modifier = KMOD_MODE;
slouken@9678
   734
        break;
slouken@9678
   735
    default:
slouken@9678
   736
        modifier = KMOD_NONE;
slouken@9678
   737
        break;
slouken@9678
   738
    }
slouken@9678
   739
    if (SDL_KEYDOWN == type) {
slouken@9678
   740
        modstate = keyboard->modstate;
slouken@9678
   741
        switch (keycode) {
slouken@9678
   742
        case SDLK_NUMLOCKCLEAR:
slouken@9678
   743
            keyboard->modstate ^= KMOD_NUM;
slouken@9678
   744
            break;
slouken@9678
   745
        case SDLK_CAPSLOCK:
slouken@9678
   746
            keyboard->modstate ^= KMOD_CAPS;
slouken@9678
   747
            break;
slouken@9678
   748
        default:
slouken@9678
   749
            keyboard->modstate |= modifier;
slouken@9678
   750
            break;
slouken@9678
   751
        }
slouken@9678
   752
    } else {
slouken@9678
   753
        keyboard->modstate &= ~modifier;
slouken@9678
   754
        modstate = keyboard->modstate;
slouken@9678
   755
    }
slouken@9678
   756
slouken@1895
   757
    /* Post the event, if desired */
slouken@1895
   758
    posted = 0;
slouken@4429
   759
    if (SDL_GetEventState(type) == SDL_ENABLE) {
slouken@1895
   760
        SDL_Event event;
slouken@1895
   761
        event.key.type = type;
slouken@1895
   762
        event.key.state = state;
slouken@4565
   763
        event.key.repeat = repeat;
slouken@1895
   764
        event.key.keysym.scancode = scancode;
slouken@9678
   765
        event.key.keysym.sym = keycode;
slouken@1895
   766
        event.key.keysym.mod = modstate;
gzjjgod@4437
   767
        event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
slouken@1895
   768
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   769
    }
slouken@1895
   770
    return (posted);
slouken@1895
   771
}
slouken@1895
   772
slouken@1895
   773
int
slouken@4465
   774
SDL_SendKeyboardText(const char *text)
slouken@1895
   775
{
slouken@4465
   776
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@1895
   777
    int posted;
slouken@1895
   778
slouken@4529
   779
    /* Don't post text events for unprintable characters */
slouken@4567
   780
    if ((unsigned char)*text < ' ' || *text == 127) {
slouken@4529
   781
        return 0;
slouken@4529
   782
    }
slouken@4529
   783
slouken@1895
   784
    /* Post the event, if desired */
slouken@1895
   785
    posted = 0;
slouken@4429
   786
    if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
slouken@1895
   787
        SDL_Event event;
slouken@1895
   788
        event.text.type = SDL_TEXTINPUT;
slouken@4435
   789
        event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
dewyatt@4754
   790
        SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
slouken@1895
   791
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   792
    }
slouken@1895
   793
    return (posted);
slouken@0
   794
}
slouken@0
   795
slouken@3280
   796
int
slouken@4465
   797
SDL_SendEditingText(const char *text, int start, int length)
slouken@3280
   798
{
slouken@4465
   799
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@3280
   800
    int posted;
slouken@3280
   801
slouken@3280
   802
    /* Post the event, if desired */
slouken@3280
   803
    posted = 0;
slouken@4429
   804
    if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) {
slouken@3280
   805
        SDL_Event event;
slouken@3280
   806
        event.edit.type = SDL_TEXTEDITING;
slouken@4435
   807
        event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
slouken@3280
   808
        event.edit.start = start;
slouken@3280
   809
        event.edit.length = length;
dewyatt@4754
   810
        SDL_utf8strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
slouken@3280
   811
        posted = (SDL_PushEvent(&event) > 0);
slouken@3280
   812
    }
slouken@3280
   813
    return (posted);
slouken@3280
   814
}
slouken@3280
   815
slouken@2303
   816
void
slouken@2303
   817
SDL_KeyboardQuit(void)
slouken@2303
   818
{
slouken@2303
   819
}
slouken@2303
   820
slouken@7258
   821
const Uint8 *
slouken@2303
   822
SDL_GetKeyboardState(int *numkeys)
slouken@2303
   823
{
slouken@4465
   824
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@2303
   825
slouken@2303
   826
    if (numkeys != (int *) 0) {
slouken@2303
   827
        *numkeys = SDL_NUM_SCANCODES;
slouken@2303
   828
    }
slouken@2303
   829
    return keyboard->keystate;
slouken@2303
   830
}
slouken@2303
   831
slouken@5220
   832
SDL_Keymod
slouken@2303
   833
SDL_GetModState(void)
slouken@2303
   834
{
slouken@4465
   835
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@2303
   836
slouken@2303
   837
    return keyboard->modstate;
slouken@2303
   838
}
slouken@2303
   839
slouken@2303
   840
void
slouken@5220
   841
SDL_SetModState(SDL_Keymod modstate)
slouken@2303
   842
{
slouken@4465
   843
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@2303
   844
slouken@2303
   845
    keyboard->modstate = modstate;
slouken@2303
   846
}
slouken@2303
   847
slouken@5220
   848
SDL_Keycode
slouken@5218
   849
SDL_GetKeyFromScancode(SDL_Scancode scancode)
slouken@2303
   850
{
slouken@4465
   851
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@7191
   852
aschiffler@6983
   853
    if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
aschiffler@6813
   854
          SDL_InvalidParamError("scancode");
aschiffler@6813
   855
          return 0;
aschiffler@6813
   856
    }
slouken@2303
   857
slouken@2303
   858
    return keyboard->keymap[scancode];
slouken@2303
   859
}
slouken@2303
   860
slouken@5218
   861
SDL_Scancode
slouken@5220
   862
SDL_GetScancodeFromKey(SDL_Keycode key)
slouken@2303
   863
{
slouken@4465
   864
    SDL_Keyboard *keyboard = &SDL_keyboard;
slouken@5218
   865
    SDL_Scancode scancode;
slouken@2303
   866
slouken@2303
   867
    for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
slouken@2303
   868
         ++scancode) {
slouken@2303
   869
        if (keyboard->keymap[scancode] == key) {
slouken@2303
   870
            return scancode;
slouken@2303
   871
        }
slouken@2303
   872
    }
slouken@2303
   873
    return SDL_SCANCODE_UNKNOWN;
slouken@2303
   874
}
slouken@2303
   875
slouken@2303
   876
const char *
slouken@5218
   877
SDL_GetScancodeName(SDL_Scancode scancode)
slouken@2303
   878
{
aschiffler@6983
   879
    const char *name;
aschiffler@6983
   880
    if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
aschiffler@6983
   881
          SDL_InvalidParamError("scancode");
slouken@7191
   882
          return "";
aschiffler@6983
   883
    }
slouken@2303
   884
aschiffler@6983
   885
    name = SDL_scancode_names[scancode];
slouken@2303
   886
    if (name)
slouken@2303
   887
        return name;
slouken@2303
   888
    else
slouken@2303
   889
        return "";
slouken@2303
   890
}
slouken@2303
   891
slouken@6029
   892
SDL_Scancode SDL_GetScancodeFromName(const char *name)
slouken@6029
   893
{
slouken@7191
   894
    int i;
slouken@6029
   895
slouken@7191
   896
    if (!name || !*name) {
slouken@7191
   897
            SDL_InvalidParamError("name");
slouken@7191
   898
        return SDL_SCANCODE_UNKNOWN;
slouken@7191
   899
    }
slouken@6029
   900
slouken@7191
   901
    for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
slouken@7191
   902
        if (!SDL_scancode_names[i]) {
slouken@7191
   903
            continue;
slouken@7191
   904
        }
slouken@7191
   905
        if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
slouken@7191
   906
            return (SDL_Scancode)i;
slouken@7191
   907
        }
slouken@7191
   908
    }
aschiffler@6811
   909
slouken@7191
   910
    SDL_InvalidParamError("name");
slouken@7191
   911
    return SDL_SCANCODE_UNKNOWN;
slouken@6029
   912
}
slouken@6029
   913
slouken@2303
   914
const char *
slouken@5220
   915
SDL_GetKeyName(SDL_Keycode key)
slouken@2303
   916
{
slouken@2303
   917
    static char name[8];
slouken@2303
   918
    char *end;
slouken@2303
   919
slouken@2303
   920
    if (key & SDLK_SCANCODE_MASK) {
slouken@2303
   921
        return
slouken@5218
   922
            SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
slouken@2303
   923
    }
slouken@2303
   924
slouken@2989
   925
    switch (key) {
slouken@2989
   926
    case SDLK_RETURN:
slouken@2990
   927
        return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
slouken@2989
   928
    case SDLK_ESCAPE:
slouken@2990
   929
        return SDL_GetScancodeName(SDL_SCANCODE_ESCAPE);
slouken@2989
   930
    case SDLK_BACKSPACE:
slouken@2990
   931
        return SDL_GetScancodeName(SDL_SCANCODE_BACKSPACE);
slouken@2989
   932
    case SDLK_TAB:
slouken@2990
   933
        return SDL_GetScancodeName(SDL_SCANCODE_TAB);
slouken@2989
   934
    case SDLK_SPACE:
slouken@2990
   935
        return SDL_GetScancodeName(SDL_SCANCODE_SPACE);
slouken@2989
   936
    case SDLK_DELETE:
slouken@2990
   937
        return SDL_GetScancodeName(SDL_SCANCODE_DELETE);
slouken@2989
   938
    default:
slouken@2989
   939
        /* Unaccented letter keys on latin keyboards are normally
slouken@2989
   940
           labeled in upper case (and probably on others like Greek or
slouken@2989
   941
           Cyrillic too, so if you happen to know for sure, please
slouken@2989
   942
           adapt this). */
slouken@2989
   943
        if (key >= 'a' && key <= 'z') {
slouken@2989
   944
            key -= 32;
slouken@2989
   945
        }
slouken@2989
   946
slouken@2989
   947
        end = SDL_UCS4ToUTF8((Uint32) key, name);
slouken@2989
   948
        *end = '\0';
slouken@2989
   949
        return name;
slouken@2303
   950
    }
slouken@2303
   951
}
slouken@2303
   952
slouken@6029
   953
SDL_Keycode
slouken@6029
   954
SDL_GetKeyFromName(const char *name)
slouken@6029
   955
{
slouken@7191
   956
    SDL_Keycode key;
slouken@6029
   957
aschiffler@6803
   958
        /* Check input */
aschiffler@6803
   959
        if (name == NULL) return SDLK_UNKNOWN;
slouken@6029
   960
slouken@7191
   961
    /* If it's a single UTF-8 character, then that's the keycode itself */
slouken@7191
   962
    key = *(const unsigned char *)name;
slouken@7191
   963
    if (key >= 0xF0) {
slouken@7191
   964
        if (SDL_strlen(name) == 4) {
slouken@7191
   965
            int i = 0;
slouken@7191
   966
            key  = (Uint16)(name[i]&0x07) << 18;
slouken@7191
   967
            key |= (Uint16)(name[++i]&0x3F) << 12;
slouken@7191
   968
            key |= (Uint16)(name[++i]&0x3F) << 6;
slouken@7191
   969
            key |= (Uint16)(name[++i]&0x3F);
slouken@7191
   970
            return key;
slouken@7191
   971
        }
slouken@7191
   972
        return SDLK_UNKNOWN;
slouken@7191
   973
    } else if (key >= 0xE0) {
slouken@7191
   974
        if (SDL_strlen(name) == 3) {
slouken@7191
   975
            int i = 0;
slouken@7191
   976
            key  = (Uint16)(name[i]&0x0F) << 12;
slouken@7191
   977
            key |= (Uint16)(name[++i]&0x3F) << 6;
slouken@7191
   978
            key |= (Uint16)(name[++i]&0x3F);
slouken@7191
   979
            return key;
slouken@7191
   980
        }
slouken@7191
   981
        return SDLK_UNKNOWN;
slouken@7191
   982
    } else if (key >= 0xC0) {
slouken@7191
   983
        if (SDL_strlen(name) == 2) {
slouken@7191
   984
            int i = 0;
slouken@7191
   985
            key  = (Uint16)(name[i]&0x1F) << 6;
slouken@7191
   986
            key |= (Uint16)(name[++i]&0x3F);
slouken@7191
   987
            return key;
slouken@7191
   988
        }
slouken@7191
   989
        return SDLK_UNKNOWN;
slouken@7191
   990
    } else {
slouken@7191
   991
        if (SDL_strlen(name) == 1) {
slouken@7191
   992
            if (key >= 'A' && key <= 'Z') {
slouken@7191
   993
                key += 32;
slouken@7191
   994
            }
slouken@7191
   995
            return key;
slouken@7191
   996
        }
slouken@7191
   997
slouken@7191
   998
        /* Get the scancode for this name, and the associated keycode */
slouken@7191
   999
        return SDL_default_keymap[SDL_GetScancodeFromName(name)];
slouken@7191
  1000
    }
slouken@6029
  1001
}
slouken@6029
  1002
slouken@1895
  1003
/* vi: set ts=4 sw=4 expandtab: */