Mercurial > sdl-ios-xcode
comparison src/events/SDL_keyboard.c @ 1673:624e1412fbba SDL-1.3
Keyboard code update in progress
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 10 Jun 2006 09:11:59 +0000 |
parents | eef792d31de8 |
children | 7688a73b25b1 |
comparison
equal
deleted
inserted
replaced
1672:8e754b82cecc | 1673:624e1412fbba |
---|---|
27 #include "SDL_events.h" | 27 #include "SDL_events.h" |
28 #include "SDL_events_c.h" | 28 #include "SDL_events_c.h" |
29 #include "SDL_sysevents.h" | 29 #include "SDL_sysevents.h" |
30 | 30 |
31 | 31 |
32 /* Global keystate information */ | 32 /* Global keyboard information */ |
33 static Uint8 SDL_KeyState[SDLK_LAST]; | 33 static int SDL_num_keyboards; |
34 static SDLMod SDL_ModState; | 34 static int SDL_current_keyboard; |
35 static SDL_Keyboard **SDL_keyboards; | |
35 int SDL_TranslateUNICODE = 0; | 36 int SDL_TranslateUNICODE = 0; |
36 | 37 |
37 static const char *keynames[SDLK_LAST]; /* Array of keycode names */ | 38 static const char *SDL_keynames[SDLK_LAST]; /* Array of keycode names */ |
38 | |
39 /* | |
40 * jk 991215 - added | |
41 */ | |
42 struct | |
43 { | |
44 int firsttime; /* if we check against the delay or repeat value */ | |
45 int delay; /* the delay before we start repeating */ | |
46 int interval; /* the delay between key repeat events */ | |
47 Uint32 timestamp; /* the time the first keydown event occurred */ | |
48 | |
49 SDL_Event evt; /* the event we are supposed to repeat */ | |
50 } SDL_KeyRepeat; | |
51 | 39 |
52 /* Public functions */ | 40 /* Public functions */ |
53 int | 41 int |
54 SDL_KeyboardInit(void) | 42 SDL_KeyboardInit(void) |
55 { | 43 { |
56 SDL_VideoDevice *_this = SDL_GetVideoDevice(); | 44 int i; |
57 | 45 |
58 /* Set default mode of UNICODE translation */ | 46 /* Set default mode of UNICODE translation */ |
59 SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); | 47 SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); |
60 | 48 |
49 /* Set default keyboard repeat setting */ | |
50 SDL_EnableKeyRepeat(0, 0); | |
51 | |
61 /* Initialize the tables */ | 52 /* Initialize the tables */ |
62 SDL_ModState = KMOD_NONE; | 53 for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) { |
63 SDL_memset((void *) keynames, 0, sizeof(keynames)); | 54 switch (i) { |
64 SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState)); | 55 case SDLK_BACKSPACE: |
65 _this->InitOSKeymap(_this); | 56 SDL_keynames[i] = "backspace"; |
66 | 57 break; |
67 SDL_EnableKeyRepeat(0, 0); | 58 case SDLK_TAB: |
68 | 59 SDL_keynames[i] = "tab"; |
69 /* Fill in the blanks in keynames */ | 60 break; |
70 keynames[SDLK_BACKSPACE] = "backspace"; | 61 case SDLK_CLEAR: |
71 keynames[SDLK_TAB] = "tab"; | 62 SDL_keynames[i] = "clear"; |
72 keynames[SDLK_CLEAR] = "clear"; | 63 break; |
73 keynames[SDLK_RETURN] = "return"; | 64 case SDLK_RETURN: |
74 keynames[SDLK_PAUSE] = "pause"; | 65 SDL_keynames[i] = "return"; |
75 keynames[SDLK_ESCAPE] = "escape"; | 66 break; |
76 keynames[SDLK_SPACE] = "space"; | 67 case SDLK_PAUSE: |
77 keynames[SDLK_EXCLAIM] = "!"; | 68 SDL_keynames[i] = "pause"; |
78 keynames[SDLK_QUOTEDBL] = "\""; | 69 break; |
79 keynames[SDLK_HASH] = "#"; | 70 case SDLK_ESCAPE: |
80 keynames[SDLK_DOLLAR] = "$"; | 71 SDL_keynames[i] = "escape"; |
81 keynames[SDLK_AMPERSAND] = "&"; | 72 break; |
82 keynames[SDLK_QUOTE] = "'"; | 73 case SDLK_SPACE: |
83 keynames[SDLK_LEFTPAREN] = "("; | 74 SDL_keynames[i] = "space"; |
84 keynames[SDLK_RIGHTPAREN] = ")"; | 75 break; |
85 keynames[SDLK_ASTERISK] = "*"; | 76 |
86 keynames[SDLK_PLUS] = "+"; | 77 case SDLK_KP0: |
87 keynames[SDLK_COMMA] = ","; | 78 SDL_keynames[i] = "[0]"; |
88 keynames[SDLK_MINUS] = "-"; | 79 break; |
89 keynames[SDLK_PERIOD] = "."; | 80 case SDLK_KP1: |
90 keynames[SDLK_SLASH] = "/"; | 81 SDL_keynames[i] = "[1]"; |
91 keynames[SDLK_0] = "0"; | 82 break; |
92 keynames[SDLK_1] = "1"; | 83 case SDLK_KP2: |
93 keynames[SDLK_2] = "2"; | 84 SDL_keynames[i] = "[2]"; |
94 keynames[SDLK_3] = "3"; | 85 break; |
95 keynames[SDLK_4] = "4"; | 86 case SDLK_KP3: |
96 keynames[SDLK_5] = "5"; | 87 SDL_keynames[i] = "[3]"; |
97 keynames[SDLK_6] = "6"; | 88 break; |
98 keynames[SDLK_7] = "7"; | 89 case SDLK_KP4: |
99 keynames[SDLK_8] = "8"; | 90 SDL_keynames[i] = "[4]"; |
100 keynames[SDLK_9] = "9"; | 91 break; |
101 keynames[SDLK_COLON] = ":"; | 92 case SDLK_KP5: |
102 keynames[SDLK_SEMICOLON] = ";"; | 93 SDL_keynames[i] = "[5]"; |
103 keynames[SDLK_LESS] = "<"; | 94 break; |
104 keynames[SDLK_EQUALS] = "="; | 95 case SDLK_KP6: |
105 keynames[SDLK_GREATER] = ">"; | 96 SDL_keynames[i] = "[6]"; |
106 keynames[SDLK_QUESTION] = "?"; | 97 break; |
107 keynames[SDLK_AT] = "@"; | 98 case SDLK_KP7: |
108 keynames[SDLK_LEFTBRACKET] = "["; | 99 SDL_keynames[i] = "[7]"; |
109 keynames[SDLK_BACKSLASH] = "\\"; | 100 break; |
110 keynames[SDLK_RIGHTBRACKET] = "]"; | 101 case SDLK_KP8: |
111 keynames[SDLK_CARET] = "^"; | 102 SDL_keynames[i] = "[8]"; |
112 keynames[SDLK_UNDERSCORE] = "_"; | 103 break; |
113 keynames[SDLK_BACKQUOTE] = "`"; | 104 case SDLK_KP9: |
114 keynames[SDLK_a] = "a"; | 105 SDL_keynames[i] = "[9]"; |
115 keynames[SDLK_b] = "b"; | 106 break; |
116 keynames[SDLK_c] = "c"; | 107 case SDLK_KP_PERIOD: |
117 keynames[SDLK_d] = "d"; | 108 SDL_keynames[i] = "[.]"; |
118 keynames[SDLK_e] = "e"; | 109 break; |
119 keynames[SDLK_f] = "f"; | 110 case SDLK_KP_DIVIDE: |
120 keynames[SDLK_g] = "g"; | 111 SDL_keynames[i] = "[/]"; |
121 keynames[SDLK_h] = "h"; | 112 break; |
122 keynames[SDLK_i] = "i"; | 113 case SDLK_KP_MULTIPLY: |
123 keynames[SDLK_j] = "j"; | 114 SDL_keynames[i] = "[*]"; |
124 keynames[SDLK_k] = "k"; | 115 break; |
125 keynames[SDLK_l] = "l"; | 116 case SDLK_KP_MINUS: |
126 keynames[SDLK_m] = "m"; | 117 SDL_keynames[i] = "[-]"; |
127 keynames[SDLK_n] = "n"; | 118 break; |
128 keynames[SDLK_o] = "o"; | 119 case SDLK_KP_PLUS: |
129 keynames[SDLK_p] = "p"; | 120 SDL_keynames[i] = "[+]"; |
130 keynames[SDLK_q] = "q"; | 121 break; |
131 keynames[SDLK_r] = "r"; | 122 case SDLK_KP_ENTER: |
132 keynames[SDLK_s] = "s"; | 123 SDL_keynames[i] = "enter"; |
133 keynames[SDLK_t] = "t"; | 124 break; |
134 keynames[SDLK_u] = "u"; | 125 case SDLK_KP_EQUALS: |
135 keynames[SDLK_v] = "v"; | 126 SDL_keynames[i] = "equals"; |
136 keynames[SDLK_w] = "w"; | 127 break; |
137 keynames[SDLK_x] = "x"; | 128 |
138 keynames[SDLK_y] = "y"; | 129 case SDLK_UP: |
139 keynames[SDLK_z] = "z"; | 130 SDL_keynames[i] = "up"; |
140 keynames[SDLK_DELETE] = "delete"; | 131 break; |
141 | 132 case SDLK_DOWN: |
142 keynames[SDLK_WORLD_0] = "world 0"; | 133 SDL_keynames[i] = "down"; |
143 keynames[SDLK_WORLD_1] = "world 1"; | 134 break; |
144 keynames[SDLK_WORLD_2] = "world 2"; | 135 case SDLK_RIGHT: |
145 keynames[SDLK_WORLD_3] = "world 3"; | 136 SDL_keynames[i] = "right"; |
146 keynames[SDLK_WORLD_4] = "world 4"; | 137 break; |
147 keynames[SDLK_WORLD_5] = "world 5"; | 138 case SDLK_LEFT: |
148 keynames[SDLK_WORLD_6] = "world 6"; | 139 SDL_keynames[i] = "left"; |
149 keynames[SDLK_WORLD_7] = "world 7"; | 140 break; |
150 keynames[SDLK_WORLD_8] = "world 8"; | 141 case SDLK_DOWN: |
151 keynames[SDLK_WORLD_9] = "world 9"; | 142 SDL_keynames[i] = "down"; |
152 keynames[SDLK_WORLD_10] = "world 10"; | 143 break; |
153 keynames[SDLK_WORLD_11] = "world 11"; | 144 case SDLK_INSERT: |
154 keynames[SDLK_WORLD_12] = "world 12"; | 145 SDL_keynames[i] = "insert"; |
155 keynames[SDLK_WORLD_13] = "world 13"; | 146 break; |
156 keynames[SDLK_WORLD_14] = "world 14"; | 147 case SDLK_HOME: |
157 keynames[SDLK_WORLD_15] = "world 15"; | 148 SDL_keynames[i] = "home"; |
158 keynames[SDLK_WORLD_16] = "world 16"; | 149 break; |
159 keynames[SDLK_WORLD_17] = "world 17"; | 150 case SDLK_END: |
160 keynames[SDLK_WORLD_18] = "world 18"; | 151 SDL_keynames[i] = "end"; |
161 keynames[SDLK_WORLD_19] = "world 19"; | 152 break; |
162 keynames[SDLK_WORLD_20] = "world 20"; | 153 case SDLK_PAGEUP: |
163 keynames[SDLK_WORLD_21] = "world 21"; | 154 SDL_keynames[i] = "page up"; |
164 keynames[SDLK_WORLD_22] = "world 22"; | 155 break; |
165 keynames[SDLK_WORLD_23] = "world 23"; | 156 case SDLK_PAGEDOWN: |
166 keynames[SDLK_WORLD_24] = "world 24"; | 157 SDL_keynames[i] = "page down"; |
167 keynames[SDLK_WORLD_25] = "world 25"; | 158 break; |
168 keynames[SDLK_WORLD_26] = "world 26"; | 159 |
169 keynames[SDLK_WORLD_27] = "world 27"; | 160 case SDLK_F1: |
170 keynames[SDLK_WORLD_28] = "world 28"; | 161 SDL_keynames[i] = "f1"; |
171 keynames[SDLK_WORLD_29] = "world 29"; | 162 break; |
172 keynames[SDLK_WORLD_30] = "world 30"; | 163 case SDLK_F2: |
173 keynames[SDLK_WORLD_31] = "world 31"; | 164 SDL_keynames[i] = "f2"; |
174 keynames[SDLK_WORLD_32] = "world 32"; | 165 break; |
175 keynames[SDLK_WORLD_33] = "world 33"; | 166 case SDLK_F3: |
176 keynames[SDLK_WORLD_34] = "world 34"; | 167 SDL_keynames[i] = "f3"; |
177 keynames[SDLK_WORLD_35] = "world 35"; | 168 break; |
178 keynames[SDLK_WORLD_36] = "world 36"; | 169 case SDLK_F4: |
179 keynames[SDLK_WORLD_37] = "world 37"; | 170 SDL_keynames[i] = "f4"; |
180 keynames[SDLK_WORLD_38] = "world 38"; | 171 break; |
181 keynames[SDLK_WORLD_39] = "world 39"; | 172 case SDLK_F5: |
182 keynames[SDLK_WORLD_40] = "world 40"; | 173 SDL_keynames[i] = "f5"; |
183 keynames[SDLK_WORLD_41] = "world 41"; | 174 break; |
184 keynames[SDLK_WORLD_42] = "world 42"; | 175 case SDLK_F6: |
185 keynames[SDLK_WORLD_43] = "world 43"; | 176 SDL_keynames[i] = "f6"; |
186 keynames[SDLK_WORLD_44] = "world 44"; | 177 break; |
187 keynames[SDLK_WORLD_45] = "world 45"; | 178 case SDLK_F7: |
188 keynames[SDLK_WORLD_46] = "world 46"; | 179 SDL_keynames[i] = "f7"; |
189 keynames[SDLK_WORLD_47] = "world 47"; | 180 break; |
190 keynames[SDLK_WORLD_48] = "world 48"; | 181 case SDLK_F8: |
191 keynames[SDLK_WORLD_49] = "world 49"; | 182 SDL_keynames[i] = "f8"; |
192 keynames[SDLK_WORLD_50] = "world 50"; | 183 break; |
193 keynames[SDLK_WORLD_51] = "world 51"; | 184 case SDLK_F9: |
194 keynames[SDLK_WORLD_52] = "world 52"; | 185 SDL_keynames[i] = "f9"; |
195 keynames[SDLK_WORLD_53] = "world 53"; | 186 break; |
196 keynames[SDLK_WORLD_54] = "world 54"; | 187 case SDLK_F10: |
197 keynames[SDLK_WORLD_55] = "world 55"; | 188 SDL_keynames[i] = "f10"; |
198 keynames[SDLK_WORLD_56] = "world 56"; | 189 break; |
199 keynames[SDLK_WORLD_57] = "world 57"; | 190 case SDLK_F11: |
200 keynames[SDLK_WORLD_58] = "world 58"; | 191 SDL_keynames[i] = "f11"; |
201 keynames[SDLK_WORLD_59] = "world 59"; | 192 break; |
202 keynames[SDLK_WORLD_60] = "world 60"; | 193 case SDLK_F12: |
203 keynames[SDLK_WORLD_61] = "world 61"; | 194 SDL_keynames[i] = "f12"; |
204 keynames[SDLK_WORLD_62] = "world 62"; | 195 break; |
205 keynames[SDLK_WORLD_63] = "world 63"; | 196 case SDLK_F13: |
206 keynames[SDLK_WORLD_64] = "world 64"; | 197 SDL_keynames[i] = "f13"; |
207 keynames[SDLK_WORLD_65] = "world 65"; | 198 break; |
208 keynames[SDLK_WORLD_66] = "world 66"; | 199 case SDLK_F14: |
209 keynames[SDLK_WORLD_67] = "world 67"; | 200 SDL_keynames[i] = "f14"; |
210 keynames[SDLK_WORLD_68] = "world 68"; | 201 break; |
211 keynames[SDLK_WORLD_69] = "world 69"; | 202 case SDLK_F15: |
212 keynames[SDLK_WORLD_70] = "world 70"; | 203 SDL_keynames[i] = "f15"; |
213 keynames[SDLK_WORLD_71] = "world 71"; | 204 break; |
214 keynames[SDLK_WORLD_72] = "world 72"; | 205 |
215 keynames[SDLK_WORLD_73] = "world 73"; | 206 case SDLK_NUMLOCK: |
216 keynames[SDLK_WORLD_74] = "world 74"; | 207 SDL_keynames[i] = "numlock"; |
217 keynames[SDLK_WORLD_75] = "world 75"; | 208 break; |
218 keynames[SDLK_WORLD_76] = "world 76"; | 209 case SDLK_CAPSLOCK: |
219 keynames[SDLK_WORLD_77] = "world 77"; | 210 SDL_keynames[i] = "caps lock"; |
220 keynames[SDLK_WORLD_78] = "world 78"; | 211 break; |
221 keynames[SDLK_WORLD_79] = "world 79"; | 212 case SDLK_SCROLLOCK: |
222 keynames[SDLK_WORLD_80] = "world 80"; | 213 SDL_keynames[i] = "scroll lock"; |
223 keynames[SDLK_WORLD_81] = "world 81"; | 214 break; |
224 keynames[SDLK_WORLD_82] = "world 82"; | 215 case SDLK_RSHIFT: |
225 keynames[SDLK_WORLD_83] = "world 83"; | 216 SDL_keynames[i] = "right shift"; |
226 keynames[SDLK_WORLD_84] = "world 84"; | 217 break; |
227 keynames[SDLK_WORLD_85] = "world 85"; | 218 case SDLK_LSHIFT: |
228 keynames[SDLK_WORLD_86] = "world 86"; | 219 SDL_keynames[i] = "left shift"; |
229 keynames[SDLK_WORLD_87] = "world 87"; | 220 break; |
230 keynames[SDLK_WORLD_88] = "world 88"; | 221 case SDLK_RCTRL: |
231 keynames[SDLK_WORLD_89] = "world 89"; | 222 SDL_keynames[i] = "right ctrl"; |
232 keynames[SDLK_WORLD_90] = "world 90"; | 223 break; |
233 keynames[SDLK_WORLD_91] = "world 91"; | 224 case SDLK_LCTRL: |
234 keynames[SDLK_WORLD_92] = "world 92"; | 225 SDL_keynames[i] = "left ctrl"; |
235 keynames[SDLK_WORLD_93] = "world 93"; | 226 break; |
236 keynames[SDLK_WORLD_94] = "world 94"; | 227 case SDLK_RALT: |
237 keynames[SDLK_WORLD_95] = "world 95"; | 228 SDL_keynames[i] = "right alt"; |
238 | 229 break; |
239 keynames[SDLK_KP0] = "[0]"; | 230 case SDLK_LALT: |
240 keynames[SDLK_KP1] = "[1]"; | 231 SDL_keynames[i] = "left alt"; |
241 keynames[SDLK_KP2] = "[2]"; | 232 break; |
242 keynames[SDLK_KP3] = "[3]"; | 233 case SDLK_RMETA: |
243 keynames[SDLK_KP4] = "[4]"; | 234 SDL_keynames[i] = "right meta"; |
244 keynames[SDLK_KP5] = "[5]"; | 235 break; |
245 keynames[SDLK_KP6] = "[6]"; | 236 case SDLK_LMETA: |
246 keynames[SDLK_KP7] = "[7]"; | 237 SDL_keynames[i] = "left meta"; |
247 keynames[SDLK_KP8] = "[8]"; | 238 break; |
248 keynames[SDLK_KP9] = "[9]"; | 239 case SDLK_LSUPER: |
249 keynames[SDLK_KP_PERIOD] = "[.]"; | 240 SDL_keynames[i] = "left super"; /* "Windows" keys */ |
250 keynames[SDLK_KP_DIVIDE] = "[/]"; | 241 break; |
251 keynames[SDLK_KP_MULTIPLY] = "[*]"; | 242 case SDLK_RSUPER: |
252 keynames[SDLK_KP_MINUS] = "[-]"; | 243 SDL_keynames[i] = "right super"; |
253 keynames[SDLK_KP_PLUS] = "[+]"; | 244 break; |
254 keynames[SDLK_KP_ENTER] = "enter"; | 245 case SDLK_MODE: |
255 keynames[SDLK_KP_EQUALS] = "equals"; | 246 SDL_keynames[i] = "alt gr"; |
256 | 247 break; |
257 keynames[SDLK_UP] = "up"; | 248 case SDLK_COMPOSE: |
258 keynames[SDLK_DOWN] = "down"; | 249 SDL_keynames[i] = "compose"; |
259 keynames[SDLK_RIGHT] = "right"; | 250 break; |
260 keynames[SDLK_LEFT] = "left"; | 251 |
261 keynames[SDLK_DOWN] = "down"; | 252 case SDLK_HELP: |
262 keynames[SDLK_INSERT] = "insert"; | 253 SDL_keynames[i] = "help"; |
263 keynames[SDLK_HOME] = "home"; | 254 break; |
264 keynames[SDLK_END] = "end"; | 255 case SDLK_PRINT: |
265 keynames[SDLK_PAGEUP] = "page up"; | 256 SDL_keynames[i] = "print screen"; |
266 keynames[SDLK_PAGEDOWN] = "page down"; | 257 break; |
267 | 258 case SDLK_SYSREQ: |
268 keynames[SDLK_F1] = "f1"; | 259 SDL_keynames[i] = "sys req"; |
269 keynames[SDLK_F2] = "f2"; | 260 break; |
270 keynames[SDLK_F3] = "f3"; | 261 case SDLK_BREAK: |
271 keynames[SDLK_F4] = "f4"; | 262 SDL_keynames[i] = "break"; |
272 keynames[SDLK_F5] = "f5"; | 263 break; |
273 keynames[SDLK_F6] = "f6"; | 264 case SDLK_MENU: |
274 keynames[SDLK_F7] = "f7"; | 265 SDL_keynames[i] = "menu"; |
275 keynames[SDLK_F8] = "f8"; | 266 break; |
276 keynames[SDLK_F9] = "f9"; | 267 case SDLK_POWER: |
277 keynames[SDLK_F10] = "f10"; | 268 SDL_keynames[i] = "power"; |
278 keynames[SDLK_F11] = "f11"; | 269 break; |
279 keynames[SDLK_F12] = "f12"; | 270 case SDLK_EURO: |
280 keynames[SDLK_F13] = "f13"; | 271 SDL_keynames[i] = "euro"; |
281 keynames[SDLK_F14] = "f14"; | 272 break; |
282 keynames[SDLK_F15] = "f15"; | 273 case SDLK_UNDO: |
283 | 274 SDL_keynames[i] = "undo"; |
284 keynames[SDLK_NUMLOCK] = "numlock"; | 275 break; |
285 keynames[SDLK_CAPSLOCK] = "caps lock"; | 276 |
286 keynames[SDLK_SCROLLOCK] = "scroll lock"; | 277 default: |
287 keynames[SDLK_RSHIFT] = "right shift"; | 278 SDL_keynames[i] = NULL; |
288 keynames[SDLK_LSHIFT] = "left shift"; | 279 break; |
289 keynames[SDLK_RCTRL] = "right ctrl"; | 280 } |
290 keynames[SDLK_LCTRL] = "left ctrl"; | 281 } |
291 keynames[SDLK_RALT] = "right alt"; | |
292 keynames[SDLK_LALT] = "left alt"; | |
293 keynames[SDLK_RMETA] = "right meta"; | |
294 keynames[SDLK_LMETA] = "left meta"; | |
295 keynames[SDLK_LSUPER] = "left super"; /* "Windows" keys */ | |
296 keynames[SDLK_RSUPER] = "right super"; | |
297 keynames[SDLK_MODE] = "alt gr"; | |
298 keynames[SDLK_COMPOSE] = "compose"; | |
299 | |
300 keynames[SDLK_HELP] = "help"; | |
301 keynames[SDLK_PRINT] = "print screen"; | |
302 keynames[SDLK_SYSREQ] = "sys req"; | |
303 keynames[SDLK_BREAK] = "break"; | |
304 keynames[SDLK_MENU] = "menu"; | |
305 keynames[SDLK_POWER] = "power"; | |
306 keynames[SDLK_EURO] = "euro"; | |
307 keynames[SDLK_UNDO] = "undo"; | |
308 | 282 |
309 /* Done. Whew. */ | 283 /* Done. Whew. */ |
310 return (0); | 284 return (0); |
311 } | 285 } |
312 | 286 |
287 SDL_Keyboard * | |
288 SDL_GetKeyboard(int index) | |
289 { | |
290 if (index < 0 || index >= SDL_num_keyboards) { | |
291 return NULL; | |
292 } | |
293 return SDL_keyboards[index]; | |
294 } | |
295 | |
296 int | |
297 SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index) | |
298 { | |
299 SDL_Keyboard **keyboards; | |
300 SDL_Cursor *cursor; | |
301 int selected_keyboard; | |
302 | |
303 /* Add the keyboard to the list of keyboards */ | |
304 if (index < 0 || index >= SDL_num_keyboards || SDL_keyboards[index]) { | |
305 keyboards = | |
306 (SDL_Keyboard **) SDL_realloc(SDL_keyboards, | |
307 (SDL_num_keyboards + | |
308 1) * sizeof(*keyboards)); | |
309 if (!keyboards) { | |
310 SDL_OutOfMemory(); | |
311 return -1; | |
312 } | |
313 | |
314 SDL_keyboards = keyboards; | |
315 index = SDL_num_keyboards++; | |
316 } | |
317 SDL_keyboards[index] = | |
318 (SDL_Keyboard *) SDL_malloc(sizeof(*SDL_keyboards[index])); | |
319 if (!SDL_keyboards[index]) { | |
320 SDL_OutOfMemory(); | |
321 return -1; | |
322 } | |
323 *SDL_keyboards[index] = *keyboard; | |
324 | |
325 return index; | |
326 } | |
327 | |
328 void | |
329 SDL_DelKeyboard(int index) | |
330 { | |
331 SDL_Keyboard *keyboard = SDL_GetKeyboard(index); | |
332 | |
333 if (!keyboard) { | |
334 return; | |
335 } | |
336 | |
337 if (keyboard->FreeKeyboard) { | |
338 keyboard->FreeKeyboard(keyboard); | |
339 } | |
340 SDL_free(keyboard); | |
341 | |
342 SDL_keyboards[index] = NULL; | |
343 } | |
344 | |
345 void | |
346 SDL_ResetKeyboard(int index) | |
347 { | |
348 SDL_Keyboard *keyboard = SDL_GetKeyboard(index); | |
349 SDL_keysym keysym; | |
350 SDLKey key; | |
351 | |
352 if (!keyboard) { | |
353 return; | |
354 } | |
355 | |
356 SDL_memset(&keysym, 0, (sizeof keysym)); | |
357 for (key = SDLK_FIRST; key < SDLK_LAST; ++key) { | |
358 if (keyboard->keystate[key] == SDL_PRESSED) { | |
359 keysym.sym = key; | |
360 SDL_SendKeyboardKey(index, SDL_RELEASED, &keysym); | |
361 } | |
362 } | |
363 keyboard->keyrepeat.timestamp = 0; | |
364 } | |
365 | |
313 void | 366 void |
314 SDL_KeyboardQuit(void) | 367 SDL_KeyboardQuit(void) |
315 { | 368 { |
316 } | 369 int i; |
317 | 370 |
318 /* We lost the keyboard, so post key up messages for all pressed keys */ | 371 for (i = 0; i < SDL_num_keyboards; ++i) { |
319 void | 372 SDL_DelKeyboard(i); |
320 SDL_ResetKeyboard(void) | 373 } |
321 { | 374 SDL_num_keyboards = 0; |
322 SDL_keysym keysym; | 375 SDL_current_keyboard = 0; |
323 SDLKey key; | 376 |
324 | 377 if (SDL_keyboards) { |
325 SDL_memset(&keysym, 0, (sizeof keysym)); | 378 SDL_free(SDL_keyboards); |
326 for (key = SDLK_FIRST; key < SDLK_LAST; ++key) { | 379 SDL_keyboards = NULL; |
327 if (SDL_KeyState[key] == SDL_PRESSED) { | 380 } |
328 keysym.sym = key; | 381 } |
329 SDL_SendKeyboard(SDL_RELEASED, &keysym); | 382 |
330 } | 383 int |
331 } | 384 SDL_GetNumKeyboards(void) |
332 SDL_KeyRepeat.timestamp = 0; | 385 { |
386 return SDL_num_keyboards; | |
387 } | |
388 | |
389 int | |
390 SDL_SelectKeyboard(int index) | |
391 { | |
392 if (index >= 0 && index < SDL_num_keyboards) { | |
393 SDL_current_keyboard = index; | |
394 } | |
395 return SDL_current_keyboard; | |
333 } | 396 } |
334 | 397 |
335 int | 398 int |
336 SDL_EnableUNICODE(int enable) | 399 SDL_EnableUNICODE(int enable) |
337 { | 400 { |
353 } | 416 } |
354 | 417 |
355 SDLMod | 418 SDLMod |
356 SDL_GetModState(void) | 419 SDL_GetModState(void) |
357 { | 420 { |
358 return (SDL_ModState); | 421 SDL_Keyboard *keyboard = SDL_GetKeyboard(index); |
422 | |
423 if (!keyboard) { | |
424 return KMOD_NONE; | |
425 } | |
426 return keyboard->modstate; | |
359 } | 427 } |
360 | 428 |
361 void | 429 void |
362 SDL_SetModState(SDLMod modstate) | 430 SDL_SetModState(SDLMod modstate) |
363 { | 431 { |
364 SDL_ModState = modstate; | 432 SDL_Keyboard *keyboard = SDL_GetKeyboard(index); |
365 } | 433 |
366 | 434 if (!keyboard) { |
367 char * | 435 return; |
436 } | |
437 keyboard->modstate = modstate; | |
438 } | |
439 | |
440 const char * | |
368 SDL_GetKeyName(SDLKey key) | 441 SDL_GetKeyName(SDLKey key) |
369 { | 442 { |
370 const char *keyname; | 443 const char *keyname; |
371 | 444 |
372 keyname = NULL; | 445 keyname = keynames[key]; |
373 if (key < SDLK_LAST) { | |
374 keyname = keynames[key]; | |
375 } | |
376 if (keyname == NULL) { | 446 if (keyname == NULL) { |
377 keyname = "unknown key"; | 447 if (key < 256) { |
378 } | 448 static char temp[4]; |
379 /* FIXME: make this function const in 1.3 */ | 449 FIXME:Convert to UTF - 8 keyname = temp; |
380 return (char *) (keyname); | 450 } else { |
451 keyname = "unknown key"; | |
452 } | |
453 } | |
454 return keyname; | |
381 } | 455 } |
382 | 456 |
383 /* These are global for SDL_eventloop.c */ | 457 /* These are global for SDL_eventloop.c */ |
384 int | 458 int |
385 SDL_SendKeyboard(Uint8 state, SDL_keysym * keysym) | 459 SDL_SendKeyboardKey(int index, Uint8 state, const SDL_keysym * keysym) |
386 { | 460 { |
387 SDL_Event event; | 461 SDL_Event event; |
388 int posted, repeatable; | 462 int posted, repeatable; |
389 Uint16 modstate; | 463 Uint16 modstate; |
390 | 464 |