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