src/events/SDL_keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 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@0
    32
/* Global keystate information */
slouken@1662
    33
static Uint8 SDL_KeyState[SDLK_LAST];
slouken@0
    34
static SDLMod SDL_ModState;
slouken@0
    35
int SDL_TranslateUNICODE = 0;
slouken@0
    36
slouken@1662
    37
static const char *keynames[SDLK_LAST]; /* Array of keycode names */
slouken@0
    38
slouken@0
    39
/*
slouken@0
    40
 * jk 991215 - added
slouken@0
    41
 */
slouken@1662
    42
struct
slouken@1662
    43
{
slouken@1662
    44
    int firsttime;              /* if we check against the delay or repeat value */
slouken@1662
    45
    int delay;                  /* the delay before we start repeating */
slouken@1662
    46
    int interval;               /* the delay between key repeat events */
slouken@1662
    47
    Uint32 timestamp;           /* the time the first keydown event occurred */
slouken@0
    48
slouken@1662
    49
    SDL_Event evt;              /* the event we are supposed to repeat */
slouken@0
    50
} SDL_KeyRepeat;
slouken@0
    51
slouken@0
    52
/* Public functions */
slouken@1662
    53
int
slouken@1662
    54
SDL_KeyboardInit (void)
slouken@0
    55
{
slouken@1662
    56
    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
slouken@0
    57
slouken@1662
    58
    /* Set default mode of UNICODE translation */
slouken@1662
    59
    SDL_EnableUNICODE (DEFAULT_UNICODE_TRANSLATION);
slouken@0
    60
slouken@1662
    61
    /* Initialize the tables */
slouken@1662
    62
    SDL_ModState = KMOD_NONE;
slouken@1662
    63
    SDL_memset ((void *) keynames, 0, sizeof (keynames));
slouken@1662
    64
    SDL_memset (SDL_KeyState, 0, sizeof (SDL_KeyState));
slouken@1662
    65
    _this->InitOSKeymap (_this);
slouken@0
    66
slouken@1662
    67
    SDL_EnableKeyRepeat (0, 0);
slouken@0
    68
slouken@1662
    69
    /* Fill in the blanks in keynames */
slouken@1662
    70
    keynames[SDLK_BACKSPACE] = "backspace";
slouken@1662
    71
    keynames[SDLK_TAB] = "tab";
slouken@1662
    72
    keynames[SDLK_CLEAR] = "clear";
slouken@1662
    73
    keynames[SDLK_RETURN] = "return";
slouken@1662
    74
    keynames[SDLK_PAUSE] = "pause";
slouken@1662
    75
    keynames[SDLK_ESCAPE] = "escape";
slouken@1662
    76
    keynames[SDLK_SPACE] = "space";
slouken@1662
    77
    keynames[SDLK_EXCLAIM] = "!";
slouken@1662
    78
    keynames[SDLK_QUOTEDBL] = "\"";
slouken@1662
    79
    keynames[SDLK_HASH] = "#";
slouken@1662
    80
    keynames[SDLK_DOLLAR] = "$";
slouken@1662
    81
    keynames[SDLK_AMPERSAND] = "&";
slouken@1662
    82
    keynames[SDLK_QUOTE] = "'";
slouken@1662
    83
    keynames[SDLK_LEFTPAREN] = "(";
slouken@1662
    84
    keynames[SDLK_RIGHTPAREN] = ")";
slouken@1662
    85
    keynames[SDLK_ASTERISK] = "*";
slouken@1662
    86
    keynames[SDLK_PLUS] = "+";
slouken@1662
    87
    keynames[SDLK_COMMA] = ",";
slouken@1662
    88
    keynames[SDLK_MINUS] = "-";
slouken@1662
    89
    keynames[SDLK_PERIOD] = ".";
slouken@1662
    90
    keynames[SDLK_SLASH] = "/";
slouken@1662
    91
    keynames[SDLK_0] = "0";
slouken@1662
    92
    keynames[SDLK_1] = "1";
slouken@1662
    93
    keynames[SDLK_2] = "2";
slouken@1662
    94
    keynames[SDLK_3] = "3";
slouken@1662
    95
    keynames[SDLK_4] = "4";
slouken@1662
    96
    keynames[SDLK_5] = "5";
slouken@1662
    97
    keynames[SDLK_6] = "6";
slouken@1662
    98
    keynames[SDLK_7] = "7";
slouken@1662
    99
    keynames[SDLK_8] = "8";
slouken@1662
   100
    keynames[SDLK_9] = "9";
slouken@1662
   101
    keynames[SDLK_COLON] = ":";
slouken@1662
   102
    keynames[SDLK_SEMICOLON] = ";";
slouken@1662
   103
    keynames[SDLK_LESS] = "<";
slouken@1662
   104
    keynames[SDLK_EQUALS] = "=";
slouken@1662
   105
    keynames[SDLK_GREATER] = ">";
slouken@1662
   106
    keynames[SDLK_QUESTION] = "?";
slouken@1662
   107
    keynames[SDLK_AT] = "@";
slouken@1662
   108
    keynames[SDLK_LEFTBRACKET] = "[";
slouken@1662
   109
    keynames[SDLK_BACKSLASH] = "\\";
slouken@1662
   110
    keynames[SDLK_RIGHTBRACKET] = "]";
slouken@1662
   111
    keynames[SDLK_CARET] = "^";
slouken@1662
   112
    keynames[SDLK_UNDERSCORE] = "_";
slouken@1662
   113
    keynames[SDLK_BACKQUOTE] = "`";
slouken@1662
   114
    keynames[SDLK_a] = "a";
slouken@1662
   115
    keynames[SDLK_b] = "b";
slouken@1662
   116
    keynames[SDLK_c] = "c";
slouken@1662
   117
    keynames[SDLK_d] = "d";
slouken@1662
   118
    keynames[SDLK_e] = "e";
slouken@1662
   119
    keynames[SDLK_f] = "f";
slouken@1662
   120
    keynames[SDLK_g] = "g";
slouken@1662
   121
    keynames[SDLK_h] = "h";
slouken@1662
   122
    keynames[SDLK_i] = "i";
slouken@1662
   123
    keynames[SDLK_j] = "j";
slouken@1662
   124
    keynames[SDLK_k] = "k";
slouken@1662
   125
    keynames[SDLK_l] = "l";
slouken@1662
   126
    keynames[SDLK_m] = "m";
slouken@1662
   127
    keynames[SDLK_n] = "n";
slouken@1662
   128
    keynames[SDLK_o] = "o";
slouken@1662
   129
    keynames[SDLK_p] = "p";
slouken@1662
   130
    keynames[SDLK_q] = "q";
slouken@1662
   131
    keynames[SDLK_r] = "r";
slouken@1662
   132
    keynames[SDLK_s] = "s";
slouken@1662
   133
    keynames[SDLK_t] = "t";
slouken@1662
   134
    keynames[SDLK_u] = "u";
slouken@1662
   135
    keynames[SDLK_v] = "v";
slouken@1662
   136
    keynames[SDLK_w] = "w";
slouken@1662
   137
    keynames[SDLK_x] = "x";
slouken@1662
   138
    keynames[SDLK_y] = "y";
slouken@1662
   139
    keynames[SDLK_z] = "z";
slouken@1662
   140
    keynames[SDLK_DELETE] = "delete";
slouken@0
   141
slouken@1662
   142
    keynames[SDLK_WORLD_0] = "world 0";
slouken@1662
   143
    keynames[SDLK_WORLD_1] = "world 1";
slouken@1662
   144
    keynames[SDLK_WORLD_2] = "world 2";
slouken@1662
   145
    keynames[SDLK_WORLD_3] = "world 3";
slouken@1662
   146
    keynames[SDLK_WORLD_4] = "world 4";
slouken@1662
   147
    keynames[SDLK_WORLD_5] = "world 5";
slouken@1662
   148
    keynames[SDLK_WORLD_6] = "world 6";
slouken@1662
   149
    keynames[SDLK_WORLD_7] = "world 7";
slouken@1662
   150
    keynames[SDLK_WORLD_8] = "world 8";
slouken@1662
   151
    keynames[SDLK_WORLD_9] = "world 9";
slouken@1662
   152
    keynames[SDLK_WORLD_10] = "world 10";
slouken@1662
   153
    keynames[SDLK_WORLD_11] = "world 11";
slouken@1662
   154
    keynames[SDLK_WORLD_12] = "world 12";
slouken@1662
   155
    keynames[SDLK_WORLD_13] = "world 13";
slouken@1662
   156
    keynames[SDLK_WORLD_14] = "world 14";
slouken@1662
   157
    keynames[SDLK_WORLD_15] = "world 15";
slouken@1662
   158
    keynames[SDLK_WORLD_16] = "world 16";
slouken@1662
   159
    keynames[SDLK_WORLD_17] = "world 17";
slouken@1662
   160
    keynames[SDLK_WORLD_18] = "world 18";
slouken@1662
   161
    keynames[SDLK_WORLD_19] = "world 19";
slouken@1662
   162
    keynames[SDLK_WORLD_20] = "world 20";
slouken@1662
   163
    keynames[SDLK_WORLD_21] = "world 21";
slouken@1662
   164
    keynames[SDLK_WORLD_22] = "world 22";
slouken@1662
   165
    keynames[SDLK_WORLD_23] = "world 23";
slouken@1662
   166
    keynames[SDLK_WORLD_24] = "world 24";
slouken@1662
   167
    keynames[SDLK_WORLD_25] = "world 25";
slouken@1662
   168
    keynames[SDLK_WORLD_26] = "world 26";
slouken@1662
   169
    keynames[SDLK_WORLD_27] = "world 27";
slouken@1662
   170
    keynames[SDLK_WORLD_28] = "world 28";
slouken@1662
   171
    keynames[SDLK_WORLD_29] = "world 29";
slouken@1662
   172
    keynames[SDLK_WORLD_30] = "world 30";
slouken@1662
   173
    keynames[SDLK_WORLD_31] = "world 31";
slouken@1662
   174
    keynames[SDLK_WORLD_32] = "world 32";
slouken@1662
   175
    keynames[SDLK_WORLD_33] = "world 33";
slouken@1662
   176
    keynames[SDLK_WORLD_34] = "world 34";
slouken@1662
   177
    keynames[SDLK_WORLD_35] = "world 35";
slouken@1662
   178
    keynames[SDLK_WORLD_36] = "world 36";
slouken@1662
   179
    keynames[SDLK_WORLD_37] = "world 37";
slouken@1662
   180
    keynames[SDLK_WORLD_38] = "world 38";
slouken@1662
   181
    keynames[SDLK_WORLD_39] = "world 39";
slouken@1662
   182
    keynames[SDLK_WORLD_40] = "world 40";
slouken@1662
   183
    keynames[SDLK_WORLD_41] = "world 41";
slouken@1662
   184
    keynames[SDLK_WORLD_42] = "world 42";
slouken@1662
   185
    keynames[SDLK_WORLD_43] = "world 43";
slouken@1662
   186
    keynames[SDLK_WORLD_44] = "world 44";
slouken@1662
   187
    keynames[SDLK_WORLD_45] = "world 45";
slouken@1662
   188
    keynames[SDLK_WORLD_46] = "world 46";
slouken@1662
   189
    keynames[SDLK_WORLD_47] = "world 47";
slouken@1662
   190
    keynames[SDLK_WORLD_48] = "world 48";
slouken@1662
   191
    keynames[SDLK_WORLD_49] = "world 49";
slouken@1662
   192
    keynames[SDLK_WORLD_50] = "world 50";
slouken@1662
   193
    keynames[SDLK_WORLD_51] = "world 51";
slouken@1662
   194
    keynames[SDLK_WORLD_52] = "world 52";
slouken@1662
   195
    keynames[SDLK_WORLD_53] = "world 53";
slouken@1662
   196
    keynames[SDLK_WORLD_54] = "world 54";
slouken@1662
   197
    keynames[SDLK_WORLD_55] = "world 55";
slouken@1662
   198
    keynames[SDLK_WORLD_56] = "world 56";
slouken@1662
   199
    keynames[SDLK_WORLD_57] = "world 57";
slouken@1662
   200
    keynames[SDLK_WORLD_58] = "world 58";
slouken@1662
   201
    keynames[SDLK_WORLD_59] = "world 59";
slouken@1662
   202
    keynames[SDLK_WORLD_60] = "world 60";
slouken@1662
   203
    keynames[SDLK_WORLD_61] = "world 61";
slouken@1662
   204
    keynames[SDLK_WORLD_62] = "world 62";
slouken@1662
   205
    keynames[SDLK_WORLD_63] = "world 63";
slouken@1662
   206
    keynames[SDLK_WORLD_64] = "world 64";
slouken@1662
   207
    keynames[SDLK_WORLD_65] = "world 65";
slouken@1662
   208
    keynames[SDLK_WORLD_66] = "world 66";
slouken@1662
   209
    keynames[SDLK_WORLD_67] = "world 67";
slouken@1662
   210
    keynames[SDLK_WORLD_68] = "world 68";
slouken@1662
   211
    keynames[SDLK_WORLD_69] = "world 69";
slouken@1662
   212
    keynames[SDLK_WORLD_70] = "world 70";
slouken@1662
   213
    keynames[SDLK_WORLD_71] = "world 71";
slouken@1662
   214
    keynames[SDLK_WORLD_72] = "world 72";
slouken@1662
   215
    keynames[SDLK_WORLD_73] = "world 73";
slouken@1662
   216
    keynames[SDLK_WORLD_74] = "world 74";
slouken@1662
   217
    keynames[SDLK_WORLD_75] = "world 75";
slouken@1662
   218
    keynames[SDLK_WORLD_76] = "world 76";
slouken@1662
   219
    keynames[SDLK_WORLD_77] = "world 77";
slouken@1662
   220
    keynames[SDLK_WORLD_78] = "world 78";
slouken@1662
   221
    keynames[SDLK_WORLD_79] = "world 79";
slouken@1662
   222
    keynames[SDLK_WORLD_80] = "world 80";
slouken@1662
   223
    keynames[SDLK_WORLD_81] = "world 81";
slouken@1662
   224
    keynames[SDLK_WORLD_82] = "world 82";
slouken@1662
   225
    keynames[SDLK_WORLD_83] = "world 83";
slouken@1662
   226
    keynames[SDLK_WORLD_84] = "world 84";
slouken@1662
   227
    keynames[SDLK_WORLD_85] = "world 85";
slouken@1662
   228
    keynames[SDLK_WORLD_86] = "world 86";
slouken@1662
   229
    keynames[SDLK_WORLD_87] = "world 87";
slouken@1662
   230
    keynames[SDLK_WORLD_88] = "world 88";
slouken@1662
   231
    keynames[SDLK_WORLD_89] = "world 89";
slouken@1662
   232
    keynames[SDLK_WORLD_90] = "world 90";
slouken@1662
   233
    keynames[SDLK_WORLD_91] = "world 91";
slouken@1662
   234
    keynames[SDLK_WORLD_92] = "world 92";
slouken@1662
   235
    keynames[SDLK_WORLD_93] = "world 93";
slouken@1662
   236
    keynames[SDLK_WORLD_94] = "world 94";
slouken@1662
   237
    keynames[SDLK_WORLD_95] = "world 95";
slouken@0
   238
slouken@1662
   239
    keynames[SDLK_KP0] = "[0]";
slouken@1662
   240
    keynames[SDLK_KP1] = "[1]";
slouken@1662
   241
    keynames[SDLK_KP2] = "[2]";
slouken@1662
   242
    keynames[SDLK_KP3] = "[3]";
slouken@1662
   243
    keynames[SDLK_KP4] = "[4]";
slouken@1662
   244
    keynames[SDLK_KP5] = "[5]";
slouken@1662
   245
    keynames[SDLK_KP6] = "[6]";
slouken@1662
   246
    keynames[SDLK_KP7] = "[7]";
slouken@1662
   247
    keynames[SDLK_KP8] = "[8]";
slouken@1662
   248
    keynames[SDLK_KP9] = "[9]";
slouken@1662
   249
    keynames[SDLK_KP_PERIOD] = "[.]";
slouken@1662
   250
    keynames[SDLK_KP_DIVIDE] = "[/]";
slouken@1662
   251
    keynames[SDLK_KP_MULTIPLY] = "[*]";
slouken@1662
   252
    keynames[SDLK_KP_MINUS] = "[-]";
slouken@1662
   253
    keynames[SDLK_KP_PLUS] = "[+]";
slouken@1662
   254
    keynames[SDLK_KP_ENTER] = "enter";
slouken@1662
   255
    keynames[SDLK_KP_EQUALS] = "equals";
slouken@0
   256
slouken@1662
   257
    keynames[SDLK_UP] = "up";
slouken@1662
   258
    keynames[SDLK_DOWN] = "down";
slouken@1662
   259
    keynames[SDLK_RIGHT] = "right";
slouken@1662
   260
    keynames[SDLK_LEFT] = "left";
slouken@1662
   261
    keynames[SDLK_DOWN] = "down";
slouken@1662
   262
    keynames[SDLK_INSERT] = "insert";
slouken@1662
   263
    keynames[SDLK_HOME] = "home";
slouken@1662
   264
    keynames[SDLK_END] = "end";
slouken@1662
   265
    keynames[SDLK_PAGEUP] = "page up";
slouken@1662
   266
    keynames[SDLK_PAGEDOWN] = "page down";
slouken@0
   267
slouken@1662
   268
    keynames[SDLK_F1] = "f1";
slouken@1662
   269
    keynames[SDLK_F2] = "f2";
slouken@1662
   270
    keynames[SDLK_F3] = "f3";
slouken@1662
   271
    keynames[SDLK_F4] = "f4";
slouken@1662
   272
    keynames[SDLK_F5] = "f5";
slouken@1662
   273
    keynames[SDLK_F6] = "f6";
slouken@1662
   274
    keynames[SDLK_F7] = "f7";
slouken@1662
   275
    keynames[SDLK_F8] = "f8";
slouken@1662
   276
    keynames[SDLK_F9] = "f9";
slouken@1662
   277
    keynames[SDLK_F10] = "f10";
slouken@1662
   278
    keynames[SDLK_F11] = "f11";
slouken@1662
   279
    keynames[SDLK_F12] = "f12";
slouken@1662
   280
    keynames[SDLK_F13] = "f13";
slouken@1662
   281
    keynames[SDLK_F14] = "f14";
slouken@1662
   282
    keynames[SDLK_F15] = "f15";
slouken@0
   283
slouken@1662
   284
    keynames[SDLK_NUMLOCK] = "numlock";
slouken@1662
   285
    keynames[SDLK_CAPSLOCK] = "caps lock";
slouken@1662
   286
    keynames[SDLK_SCROLLOCK] = "scroll lock";
slouken@1662
   287
    keynames[SDLK_RSHIFT] = "right shift";
slouken@1662
   288
    keynames[SDLK_LSHIFT] = "left shift";
slouken@1662
   289
    keynames[SDLK_RCTRL] = "right ctrl";
slouken@1662
   290
    keynames[SDLK_LCTRL] = "left ctrl";
slouken@1662
   291
    keynames[SDLK_RALT] = "right alt";
slouken@1662
   292
    keynames[SDLK_LALT] = "left alt";
slouken@1662
   293
    keynames[SDLK_RMETA] = "right meta";
slouken@1662
   294
    keynames[SDLK_LMETA] = "left meta";
slouken@1662
   295
    keynames[SDLK_LSUPER] = "left super";       /* "Windows" keys */
slouken@1662
   296
    keynames[SDLK_RSUPER] = "right super";
slouken@1662
   297
    keynames[SDLK_MODE] = "alt gr";
slouken@1662
   298
    keynames[SDLK_COMPOSE] = "compose";
slouken@0
   299
slouken@1662
   300
    keynames[SDLK_HELP] = "help";
slouken@1662
   301
    keynames[SDLK_PRINT] = "print screen";
slouken@1662
   302
    keynames[SDLK_SYSREQ] = "sys req";
slouken@1662
   303
    keynames[SDLK_BREAK] = "break";
slouken@1662
   304
    keynames[SDLK_MENU] = "menu";
slouken@1662
   305
    keynames[SDLK_POWER] = "power";
slouken@1662
   306
    keynames[SDLK_EURO] = "euro";
slouken@1662
   307
    keynames[SDLK_UNDO] = "undo";
slouken@0
   308
slouken@1662
   309
    /* Done.  Whew. */
slouken@1662
   310
    return (0);
slouken@0
   311
}
slouken@1662
   312
slouken@1662
   313
void
slouken@1662
   314
SDL_KeyboardQuit (void)
slouken@1123
   315
{
slouken@1123
   316
}
slouken@0
   317
slouken@0
   318
/* We lost the keyboard, so post key up messages for all pressed keys */
slouken@1662
   319
void
slouken@1662
   320
SDL_ResetKeyboard (void)
slouken@0
   321
{
slouken@1662
   322
    SDL_keysym keysym;
slouken@1662
   323
    SDLKey key;
slouken@0
   324
slouken@1662
   325
    SDL_memset (&keysym, 0, (sizeof keysym));
slouken@1662
   326
    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
slouken@1662
   327
        if (SDL_KeyState[key] == SDL_PRESSED) {
slouken@1662
   328
            keysym.sym = key;
slouken@1662
   329
            SDL_PrivateKeyboard (SDL_RELEASED, &keysym);
slouken@1662
   330
        }
slouken@1662
   331
    }
slouken@1662
   332
    SDL_KeyRepeat.timestamp = 0;
slouken@0
   333
}
slouken@0
   334
slouken@1662
   335
int
slouken@1662
   336
SDL_EnableUNICODE (int enable)
slouken@0
   337
{
slouken@1662
   338
    int old_mode;
slouken@0
   339
slouken@1662
   340
    old_mode = SDL_TranslateUNICODE;
slouken@1662
   341
    if (enable >= 0) {
slouken@1662
   342
        SDL_TranslateUNICODE = enable;
slouken@1662
   343
    }
slouken@1662
   344
    return (old_mode);
slouken@0
   345
}
slouken@0
   346
slouken@1662
   347
Uint8 *
slouken@1662
   348
SDL_GetKeyState (int *numkeys)
slouken@0
   349
{
slouken@1662
   350
    if (numkeys != (int *) 0)
slouken@1662
   351
        *numkeys = SDLK_LAST;
slouken@1662
   352
    return (SDL_KeyState);
slouken@0
   353
}
slouken@0
   354
slouken@1662
   355
SDLMod
slouken@1662
   356
SDL_GetModState (void)
slouken@0
   357
{
slouken@1662
   358
    return (SDL_ModState);
slouken@1662
   359
}
slouken@0
   360
slouken@1662
   361
void
slouken@1662
   362
SDL_SetModState (SDLMod modstate)
slouken@1662
   363
{
slouken@1662
   364
    SDL_ModState = modstate;
slouken@1662
   365
}
slouken@1662
   366
slouken@1662
   367
char *
slouken@1662
   368
SDL_GetKeyName (SDLKey key)
slouken@1662
   369
{
slouken@1662
   370
    const char *keyname;
slouken@1662
   371
slouken@1662
   372
    keyname = NULL;
slouken@1662
   373
    if (key < SDLK_LAST) {
slouken@1662
   374
        keyname = keynames[key];
slouken@1662
   375
    }
slouken@1662
   376
    if (keyname == NULL) {
slouken@1662
   377
        keyname = "unknown key";
slouken@1662
   378
    }
slouken@1662
   379
    /* FIXME: make this function const in 1.3 */
slouken@1662
   380
    return (char *) (keyname);
slouken@0
   381
}
slouken@0
   382
slouken@0
   383
/* These are global for SDL_eventloop.c */
slouken@1662
   384
int
slouken@1662
   385
SDL_PrivateKeyboard (Uint8 state, SDL_keysym * keysym)
slouken@0
   386
{
slouken@1662
   387
    SDL_Event event;
slouken@1662
   388
    int posted, repeatable;
slouken@1662
   389
    Uint16 modstate;
slouken@0
   390
slouken@1662
   391
    SDL_memset (&event, 0, sizeof (event));
slouken@0
   392
slouken@0
   393
#if 0
slouken@1662
   394
    printf ("The '%s' key has been %s\n", SDL_GetKeyName (keysym->sym),
slouken@1662
   395
            state == SDL_PRESSED ? "pressed" : "released");
slouken@0
   396
#endif
slouken@1662
   397
    /* Set up the keysym */
slouken@1662
   398
    modstate = (Uint16) SDL_ModState;
slouken@0
   399
slouken@1662
   400
    repeatable = 0;
slouken@0
   401
slouken@1662
   402
    if (state == SDL_PRESSED) {
slouken@1662
   403
        keysym->mod = (SDLMod) modstate;
slouken@1662
   404
        switch (keysym->sym) {
slouken@1662
   405
        case SDLK_UNKNOWN:
slouken@1662
   406
            break;
slouken@1662
   407
        case SDLK_NUMLOCK:
slouken@1662
   408
            modstate ^= KMOD_NUM;
slouken@1662
   409
            if (!(modstate & KMOD_NUM))
slouken@1662
   410
                state = SDL_RELEASED;
slouken@1662
   411
            keysym->mod = (SDLMod) modstate;
slouken@1662
   412
            break;
slouken@1662
   413
        case SDLK_CAPSLOCK:
slouken@1662
   414
            modstate ^= KMOD_CAPS;
slouken@1662
   415
            if (!(modstate & KMOD_CAPS))
slouken@1662
   416
                state = SDL_RELEASED;
slouken@1662
   417
            keysym->mod = (SDLMod) modstate;
slouken@1662
   418
            break;
slouken@1662
   419
        case SDLK_LCTRL:
slouken@1662
   420
            modstate |= KMOD_LCTRL;
slouken@1662
   421
            break;
slouken@1662
   422
        case SDLK_RCTRL:
slouken@1662
   423
            modstate |= KMOD_RCTRL;
slouken@1662
   424
            break;
slouken@1662
   425
        case SDLK_LSHIFT:
slouken@1662
   426
            modstate |= KMOD_LSHIFT;
slouken@1662
   427
            break;
slouken@1662
   428
        case SDLK_RSHIFT:
slouken@1662
   429
            modstate |= KMOD_RSHIFT;
slouken@1662
   430
            break;
slouken@1662
   431
        case SDLK_LALT:
slouken@1662
   432
            modstate |= KMOD_LALT;
slouken@1662
   433
            break;
slouken@1662
   434
        case SDLK_RALT:
slouken@1662
   435
            modstate |= KMOD_RALT;
slouken@1662
   436
            break;
slouken@1662
   437
        case SDLK_LMETA:
slouken@1662
   438
            modstate |= KMOD_LMETA;
slouken@1662
   439
            break;
slouken@1662
   440
        case SDLK_RMETA:
slouken@1662
   441
            modstate |= KMOD_RMETA;
slouken@1662
   442
            break;
slouken@1662
   443
        case SDLK_MODE:
slouken@1662
   444
            modstate |= KMOD_MODE;
slouken@1662
   445
            break;
slouken@1662
   446
        default:
slouken@1662
   447
            repeatable = 1;
slouken@1662
   448
            break;
slouken@1662
   449
        }
slouken@1662
   450
    } else {
slouken@1662
   451
        switch (keysym->sym) {
slouken@1662
   452
        case SDLK_UNKNOWN:
slouken@1662
   453
            break;
slouken@1662
   454
        case SDLK_NUMLOCK:
slouken@1662
   455
        case SDLK_CAPSLOCK:
slouken@1662
   456
            /* Only send keydown events */
slouken@1662
   457
            return (0);
slouken@1662
   458
        case SDLK_LCTRL:
slouken@1662
   459
            modstate &= ~KMOD_LCTRL;
slouken@1662
   460
            break;
slouken@1662
   461
        case SDLK_RCTRL:
slouken@1662
   462
            modstate &= ~KMOD_RCTRL;
slouken@1662
   463
            break;
slouken@1662
   464
        case SDLK_LSHIFT:
slouken@1662
   465
            modstate &= ~KMOD_LSHIFT;
slouken@1662
   466
            break;
slouken@1662
   467
        case SDLK_RSHIFT:
slouken@1662
   468
            modstate &= ~KMOD_RSHIFT;
slouken@1662
   469
            break;
slouken@1662
   470
        case SDLK_LALT:
slouken@1662
   471
            modstate &= ~KMOD_LALT;
slouken@1662
   472
            break;
slouken@1662
   473
        case SDLK_RALT:
slouken@1662
   474
            modstate &= ~KMOD_RALT;
slouken@1662
   475
            break;
slouken@1662
   476
        case SDLK_LMETA:
slouken@1662
   477
            modstate &= ~KMOD_LMETA;
slouken@1662
   478
            break;
slouken@1662
   479
        case SDLK_RMETA:
slouken@1662
   480
            modstate &= ~KMOD_RMETA;
slouken@1662
   481
            break;
slouken@1662
   482
        case SDLK_MODE:
slouken@1662
   483
            modstate &= ~KMOD_MODE;
slouken@1662
   484
            break;
slouken@1662
   485
        default:
slouken@1662
   486
            break;
slouken@1662
   487
        }
slouken@1662
   488
        keysym->mod = (SDLMod) modstate;
slouken@1662
   489
    }
slouken@0
   490
slouken@1662
   491
    /* Figure out what type of event this is */
slouken@1662
   492
    switch (state) {
slouken@1662
   493
    case SDL_PRESSED:
slouken@1662
   494
        event.type = SDL_KEYDOWN;
slouken@1662
   495
        break;
slouken@1662
   496
    case SDL_RELEASED:
slouken@1662
   497
        event.type = SDL_KEYUP;
slouken@1662
   498
        /*
slouken@1662
   499
         * jk 991215 - Added
slouken@1662
   500
         */
slouken@1662
   501
        if (SDL_KeyRepeat.timestamp &&
slouken@1662
   502
            SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym) {
slouken@1662
   503
            SDL_KeyRepeat.timestamp = 0;
slouken@1662
   504
        }
slouken@1662
   505
        break;
slouken@1662
   506
    default:
slouken@1662
   507
        /* Invalid state -- bail */
slouken@1662
   508
        return (0);
slouken@1662
   509
    }
slouken@0
   510
slouken@1662
   511
    if (keysym->sym != SDLK_UNKNOWN) {
slouken@1662
   512
        /* Drop events that don't change state */
slouken@1662
   513
        if (SDL_KeyState[keysym->sym] == state) {
slouken@1282
   514
#if 0
slouken@1662
   515
            printf ("Keyboard event didn't change state - dropped!\n");
slouken@1282
   516
#endif
slouken@1662
   517
            return (0);
slouken@1662
   518
        }
slouken@1327
   519
slouken@1662
   520
        /* Update internal keyboard state */
slouken@1662
   521
        SDL_ModState = (SDLMod) modstate;
slouken@1662
   522
        SDL_KeyState[keysym->sym] = state;
slouken@1662
   523
    }
slouken@0
   524
slouken@1662
   525
    /* Post the event, if desired */
slouken@1662
   526
    posted = 0;
slouken@1662
   527
    if (SDL_ProcessEvents[event.type] == SDL_ENABLE) {
slouken@1662
   528
        event.key.state = state;
slouken@1662
   529
        event.key.keysym = *keysym;
slouken@1662
   530
        /*
slouken@1662
   531
         * jk 991215 - Added
slouken@1662
   532
         */
slouken@1662
   533
        if (repeatable && (SDL_KeyRepeat.delay != 0)) {
slouken@1662
   534
            SDL_KeyRepeat.evt = event;
slouken@1662
   535
            SDL_KeyRepeat.firsttime = 1;
slouken@1662
   536
            SDL_KeyRepeat.timestamp = SDL_GetTicks ();
slouken@1662
   537
        }
slouken@1662
   538
        if ((SDL_EventOK == NULL) || SDL_EventOK (&event)) {
slouken@1662
   539
            posted = 1;
slouken@1662
   540
            SDL_PushEvent (&event);
slouken@1662
   541
        }
slouken@1662
   542
    }
slouken@1662
   543
    return (posted);
slouken@0
   544
}
slouken@0
   545
slouken@0
   546
/*
slouken@0
   547
 * jk 991215 - Added
slouken@0
   548
 */
slouken@1662
   549
void
slouken@1662
   550
SDL_CheckKeyRepeat (void)
slouken@0
   551
{
slouken@1662
   552
    if (SDL_KeyRepeat.timestamp) {
slouken@1662
   553
        Uint32 now, interval;
slouken@0
   554
slouken@1662
   555
        now = SDL_GetTicks ();
slouken@1662
   556
        interval = (now - SDL_KeyRepeat.timestamp);
slouken@1662
   557
        if (SDL_KeyRepeat.firsttime) {
slouken@1662
   558
            if (interval > (Uint32) SDL_KeyRepeat.delay) {
slouken@1662
   559
                SDL_KeyRepeat.timestamp = now;
slouken@1662
   560
                SDL_KeyRepeat.firsttime = 0;
slouken@1662
   561
            }
slouken@1662
   562
        } else {
slouken@1662
   563
            if (interval > (Uint32) SDL_KeyRepeat.interval) {
slouken@1662
   564
                SDL_KeyRepeat.timestamp = now;
slouken@1662
   565
                if ((SDL_EventOK == NULL)
slouken@1662
   566
                    || SDL_EventOK (&SDL_KeyRepeat.evt)) {
slouken@1662
   567
                    SDL_PushEvent (&SDL_KeyRepeat.evt);
slouken@1662
   568
                }
slouken@1662
   569
            }
slouken@1662
   570
        }
slouken@1662
   571
    }
slouken@0
   572
}
slouken@0
   573
slouken@1662
   574
int
slouken@1662
   575
SDL_EnableKeyRepeat (int delay, int interval)
slouken@0
   576
{
slouken@1662
   577
    if ((delay < 0) || (interval < 0)) {
slouken@1662
   578
        SDL_SetError ("keyboard repeat value less than zero");
slouken@1662
   579
        return (-1);
slouken@1662
   580
    }
slouken@1662
   581
    SDL_KeyRepeat.firsttime = 0;
slouken@1662
   582
    SDL_KeyRepeat.delay = delay;
slouken@1662
   583
    SDL_KeyRepeat.interval = interval;
slouken@1662
   584
    SDL_KeyRepeat.timestamp = 0;
slouken@1662
   585
    return (0);
slouken@0
   586
}
slouken@0
   587
slouken@1662
   588
void
slouken@1662
   589
SDL_GetKeyRepeat (int *delay, int *interval)
slouken@1507
   590
{
slouken@1662
   591
    *delay = SDL_KeyRepeat.delay;
slouken@1662
   592
    *interval = SDL_KeyRepeat.interval;
slouken@1507
   593
}
slouken@1507
   594
slouken@1662
   595
/* vi: set ts=4 sw=4 expandtab: */