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