Fix compiler warnings
[btb/d2x.git] / input / sdl_key.c
1 /*
2  * $Source: /cvs/cvsroot/d2x/input/sdl_key.c,v $
3  * $Revision: 1.2 $
4  * $Author: bradleyb $
5  * $Date: 2001-01-29 14:03:57 $
6  *
7  * SDL keyboard input support
8  *
9  * $Log: not supported by cvs2svn $
10  */
11
12 #ifdef HAVE_CONFIG_H
13 #include <conf.h>
14 #endif
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include <SDL/SDL.h>
20
21 #include "event.h"
22 #include "error.h"
23 #include "key.h"
24 #include "timer.h"
25
26 //added on 9/3/98 by Matt Mueller to free some cpu instead of hogging during menus and such
27 #include "d_delay.h"
28 //end this section addition - Matt Mueller
29
30 #define KEY_BUFFER_SIZE 16
31
32 static unsigned char Installed = 0;
33
34 //-------- Variable accessed by outside functions ---------
35 unsigned char           keyd_buffer_type;               // 0=No buffer, 1=buffer ASCII, 2=buffer scans
36 unsigned char           keyd_repeat;
37 unsigned char           keyd_editor_mode;
38 volatile unsigned char  keyd_last_pressed;
39 volatile unsigned char  keyd_last_released;
40 volatile unsigned char  keyd_pressed[256];
41 volatile int            keyd_time_when_last_pressed;
42
43 typedef struct Key_info {
44         ubyte           state;                  // state of key 1 == down, 0 == up
45         ubyte           last_state;             // previous state of key
46         int             counter;                // incremented each time key is down in handler
47         fix             timewentdown;   // simple counter incremented each time in interrupt and key is down
48         fix             timehelddown;   // counter to tell how long key is down -- gets reset to 0 by key routines
49         ubyte           downcount;              // number of key counts key was down
50         ubyte           upcount;                // number of times key was released
51 } Key_info;
52
53 typedef struct keyboard {
54         unsigned short          keybuffer[KEY_BUFFER_SIZE];
55         Key_info                keys[256];
56         fix                     time_pressed[KEY_BUFFER_SIZE];
57         unsigned int            keyhead, keytail;
58 } keyboard;
59
60 static keyboard key_data;
61
62 typedef struct key_props {
63         char *key_text;
64         unsigned char ascii_value;
65         unsigned char shifted_ascii_value;
66         SDLKey sym;
67 } key_props;
68
69 key_props key_properties[256] = {
70 { "",       255,    255,    -1                 },
71 { "ESC",    255,    255,    SDLK_ESCAPE        },
72 { "1",      '1',    '!',    SDLK_1             },
73 { "2",      '2',    '@',    SDLK_2             },
74 { "3",      '3',    '#',    SDLK_3             },
75 { "4",      '4',    '$',    SDLK_4             },
76 { "5",      '5',    '%',    SDLK_5             },
77 { "6",      '6',    '^',    SDLK_6             },
78 { "7",      '7',    '&',    SDLK_7             },
79 { "8",      '8',    '*',    SDLK_8             },
80 { "9",      '9',    '(',    SDLK_9             },
81 { "0",      '0',    ')',    SDLK_0             },
82 { "-",      '-',    '_',    SDLK_MINUS         },
83 { "=",      '=',    '+',    SDLK_EQUALS        },
84 { "BSPC",   255,    255,    SDLK_BACKSPACE     },
85 { "TAB",    255,    255,    SDLK_TAB           },
86 { "Q",      'q',    'Q',    SDLK_q             },
87 { "W",      'w',    'W',    SDLK_w             },
88 { "E",      'e',    'E',    SDLK_e             },
89 { "R",      'r',    'R',    SDLK_r             },
90 { "T",      't',    'T',    SDLK_t             },
91 { "Y",      'y',    'Y',    SDLK_y             },
92 { "U",      'u',    'U',    SDLK_u             },
93 { "I",      'i',    'I',    SDLK_i             },
94 { "O",      'o',    'O',    SDLK_o             },
95 { "P",      'p',    'P',    SDLK_p             },
96 { "[",      '[',    '{',    SDLK_LEFTBRACKET   },
97 { "]",      ']',    '}',    SDLK_RIGHTBRACKET  },
98 //edited 06/08/99 Matt Mueller - set to correct key_text
99 { "\83",      255,    255,    SDLK_RETURN        },
100 //end edit -MM
101 { "LCTRL",  255,    255,    SDLK_LCTRL         },
102 { "A",      'a',    'A',    SDLK_a             },
103 { "S",      's',    'S',    SDLK_s             },
104 { "D",      'd',    'D',    SDLK_d             },
105 { "F",      'f',    'F',    SDLK_f             },
106 { "G",      'g',    'G',    SDLK_g             },
107 { "H",      'h',    'H',    SDLK_h             },
108 { "J",      'j',    'J',    SDLK_j             },
109 { "K",      'k',    'K',    SDLK_k             },
110 { "L",      'l',    'L',    SDLK_l             },
111 //edited 06/08/99 Matt Mueller - set to correct sym
112 { ";",      ';',    ':',    SDLK_SEMICOLON         },
113 //end edit -MM
114 { "'",      '\'',   '"',    SDLK_QUOTE         },
115 //edited 06/08/99 Matt Mueller - set to correct sym
116 { "`",      '`',    '~',    SDLK_BACKQUOTE     },
117 //end edit -MM
118 { "LSHFT",  255,    255,    SDLK_LSHIFT        },
119 { "\\",     '\\',   '|',    SDLK_BACKSLASH     },
120 { "Z",      'z',    'Z',    SDLK_z             },
121 { "X",      'x',    'X',    SDLK_x             },
122 { "C",      'c',    'C',    SDLK_c             },
123 { "V",      'v',    'V',    SDLK_v             },
124 { "B",      'b',    'B',    SDLK_b             },
125 { "N",      'n',    'N',    SDLK_n             },
126 { "M",      'm',    'M',    SDLK_m             },
127 //edited 06/08/99 Matt Mueller - set to correct syms
128 { ",",      ',',    '<',    SDLK_COMMA  },
129 { ".",      '.',    '>',    SDLK_PERIOD },
130 { "/",      '/',    '?',    SDLK_SLASH  },
131 //end edit -MM
132 { "RSHFT",  255,    255,    SDLK_RSHIFT },
133 { "PAD*",   '*',    255,    SDLK_KP_MULTIPLY   },
134 { "LALT",   255,    255,    SDLK_LALT          },
135 { "SPC",    ' ',    ' ',    SDLK_SPACE         },
136 { "CPSLK",  255,    255,    SDLK_CAPSLOCK      },
137 { "F1",     255,    255,    SDLK_F1            },
138 { "F2",     255,    255,    SDLK_F2            },
139 { "F3",     255,    255,    SDLK_F3            },
140 { "F4",     255,    255,    SDLK_F4            },
141 { "F5",     255,    255,    SDLK_F5            },
142 { "F6",     255,    255,    SDLK_F6            },
143 { "F7",     255,    255,    SDLK_F7            },
144 { "F8",     255,    255,    SDLK_F8            },
145 { "F9",     255,    255,    SDLK_F9            },
146 { "F10",    255,    255,    SDLK_F10           },
147 { "NMLCK",  255,    255,    SDLK_NUMLOCK       },
148 { "SCLK",   255,    255,    SDLK_SCROLLOCK     },
149 { "PAD7",   255,    255,    SDLK_KP7           },
150 { "PAD8",   255,    255,    SDLK_KP8           },
151 { "PAD9",   255,    255,    SDLK_KP9           },
152 { "PAD-",   255,    255,    SDLK_KP_MINUS      },
153 { "PAD4",   255,    255,    SDLK_KP4           },
154 { "PAD5",   255,    255,    SDLK_KP5           },
155 { "PAD6",   255,    255,    SDLK_KP6           },
156 { "PAD+",   255,    255,    SDLK_KP_PLUS       },
157 { "PAD1",   255,    255,    SDLK_KP1           },
158 { "PAD2",   255,    255,    SDLK_KP2           },
159 { "PAD3",   255,    255,    SDLK_KP3           },
160 { "PAD0",   255,    255,    SDLK_KP0           },
161 { "PAD.",   255,    255,    SDLK_KP_PERIOD     },
162 { "",       255,    255,    -1                 },
163 { "",       255,    255,    -1                 },
164 { "",       255,    255,    -1                 },
165 { "F11",    255,    255,    SDLK_F11           },
166 { "F12",    255,    255,    SDLK_F12           },
167 { "",       255,    255,    -1                 },       
168 { "",       255,    255,    -1                 },
169 { "",       255,    255,    -1                 },
170 { "",       255,    255,    -1                 },
171 { "",       255,    255,    -1                 },
172 { "",       255,    255,    -1                 },
173 { "",       255,    255,    -1                 },
174 { "",       255,    255,    -1                 },
175 //edited 06/08/99 Matt Mueller - add pause ability
176 { "PAUSE",       255,    255,    SDLK_PAUSE                 },
177 //end edit -MM
178 { "",       255,    255,    -1                 },
179 { "",       255,    255,    -1                 },
180 { "",       255,    255,    -1                 },
181 { "",       255,    255,    -1                 },
182 { "",       255,    255,    -1                 },
183 { "",       255,    255,    -1                 },
184 { "",       255,    255,    -1                 },
185 { "",       255,    255,    -1                 },
186 { "",       255,    255,    -1                 },
187 { "",       255,    255,    -1                 },
188 { "",       255,    255,    -1                 },
189 { "",       255,    255,    -1                 },
190 { "",       255,    255,    -1                 },
191 { "",       255,    255,    -1                 },
192 { "",       255,    255,    -1                 },
193 { "",       255,    255,    -1                 },
194 { "",       255,    255,    -1                 },
195 { "",       255,    255,    -1                 },
196 { "",       255,    255,    -1                 },
197 { "",       255,    255,    -1                 },
198 { "",       255,    255,    -1                 },
199 { "",       255,    255,    -1                 },
200 { "",       255,    255,    -1                 },
201 { "",       255,    255,    -1                 },
202 { "",       255,    255,    -1                 },
203 { "",       255,    255,    -1                 },
204 { "",       255,    255,    -1                 },
205 { "",       255,    255,    -1                 },
206 { "",       255,    255,    -1                 },
207 { "",       255,    255,    -1                 },
208 { "",       255,    255,    -1                 },
209 { "",       255,    255,    -1                 },
210 { "",       255,    255,    -1                 },
211 { "",       255,    255,    -1                 },
212 { "",       255,    255,    -1                 },
213 { "",       255,    255,    -1                 },
214 { "",       255,    255,    -1                 },
215 { "",       255,    255,    -1                 },
216 { "",       255,    255,    -1                 },
217 { "",       255,    255,    -1                 },
218 { "",       255,    255,    -1                 },
219 { "",       255,    255,    -1                 },
220 { "",       255,    255,    -1                 },
221 { "",       255,    255,    -1                 },
222 { "",       255,    255,    -1                 },
223 { "",       255,    255,    -1                 },
224 { "",       255,    255,    -1                 },
225 { "",       255,    255,    -1                 },
226 { "",       255,    255,    -1                 },
227 { "",       255,    255,    -1                 },
228 { "",       255,    255,    -1                 },
229 { "",       255,    255,    -1                 },
230 { "",       255,    255,    -1                 },
231 { "",       255,    255,    -1                 },
232 { "",       255,    255,    -1                 },
233 { "",       255,    255,    -1                 },
234 { "",       255,    255,    -1                 },
235 { "",       255,    255,    -1                 },
236 //edited 06/08/99 Matt Mueller - set to correct key_text
237 { "PAD\83",   255,    255,    SDLK_KP_ENTER      },
238 //end edit -MM
239 //edited 06/08/99 Matt Mueller - set to correct sym
240 { "RCTRL",  255,    255,    SDLK_RCTRL            },
241 //end edit -MM
242 { "",       255,    255,    -1                 },
243 { "",       255,    255,    -1                 },
244 { "",       255,    255,    -1                 },
245 { "",       255,    255,    -1                 },
246 { "",       255,    255,    -1                 },
247 { "",       255,    255,    -1                 },
248 { "",       255,    255,    -1                 },
249 { "",       255,    255,    -1                 },
250 { "",       255,    255,    -1                 },
251 { "",       255,    255,    -1                 },
252 { "",       255,    255,    -1                 },
253 { "",       255,    255,    -1                 },
254 { "",       255,    255,    -1                 },
255 { "",       255,    255,    -1                 },
256 { "",       255,    255,    -1                 },
257 { "",       255,    255,    -1                 },
258 { "",       255,    255,    -1                 },
259 { "",       255,    255,    -1                 },
260 { "",       255,    255,    -1                 },
261 { "",       255,    255,    -1                 },
262 { "",       255,    255,    -1                 },
263 { "",       255,    255,    -1                 },
264 { "",       255,    255,    -1                 },
265 { "PAD/",   255,    255,    SDLK_KP_DIVIDE     },
266 { "",       255,    255,    -1                 },
267 //edited 06/08/99 Matt Mueller - add printscreen ability
268 { "PRSCR",       255,    255,    SDLK_PRINT                 },
269 //end edit -MM
270 { "RALT",   255,    255,    SDLK_RALT          },
271 { "",       255,    255,    -1                 },
272 { "",       255,    255,    -1                 },
273 { "",       255,    255,    -1                 },
274 { "",       255,    255,    -1                 },
275 { "",       255,    255,    -1                 },
276 { "",       255,    255,    -1                 },
277 { "",       255,    255,    -1                 },
278 { "",       255,    255,    -1                 },
279 { "",       255,    255,    -1                 },
280 { "",       255,    255,    -1                 },
281 { "",       255,    255,    -1                 },
282 { "",       255,    255,    -1                 },
283 { "",       255,    255,    -1                 },
284 { "",       255,    255,    -1                 },
285 { "HOME",   255,    255,    SDLK_HOME          },
286 //edited 06/08/99 Matt Mueller - set to correct key_text
287 { "UP",         255,    255,    SDLK_UP            },
288 //end edit -MM
289 { "PGUP",   255,    255,    SDLK_PAGEUP        },
290 { "",       255,    255,    -1                 },
291 //edited 06/08/99 Matt Mueller - set to correct key_text
292 { "LEFT",       255,    255,    SDLK_LEFT          },
293 //end edit -MM
294 { "",       255,    255,    -1                 },
295 //edited 06/08/99 Matt Mueller - set to correct key_text
296 { "RIGHT",      255,    255,    SDLK_RIGHT         },
297 //end edit -MM
298 { "",       255,    255,    -1                 },
299 //edited 06/08/99 Matt Mueller - set to correct key_text
300 { "END",    255,    255,    SDLK_END           },
301 //end edit -MM
302 { "DOWN",       255,    255,    SDLK_DOWN          },
303 { "PGDN",       255,    255,    SDLK_PAGEDOWN      },
304 { "INS",        255,    255,    SDLK_INSERT        },
305 { "DEL",        255,    255,    SDLK_DELETE        },
306 { "",       255,    255,    -1                 },
307 { "",       255,    255,    -1                 },
308 { "",       255,    255,    -1                 },
309 { "",       255,    255,    -1                 },
310 { "",       255,    255,    -1                 },
311 { "",       255,    255,    -1                 },
312 { "",       255,    255,    -1                 },
313 { "",       255,    255,    -1                 },
314 { "",       255,    255,    -1                 },
315 { "",       255,    255,    -1                 },
316 { "",       255,    255,    -1                 },
317 { "",       255,    255,    -1                 },
318 { "",       255,    255,    -1                 },
319 { "",       255,    255,    -1                 },
320 { "",       255,    255,    -1                 },
321 { "",       255,    255,    -1                 },
322 { "",       255,    255,    -1                 },
323 { "",       255,    255,    -1                 },
324 { "",       255,    255,    -1                 },
325 { "",       255,    255,    -1                 },
326 { "",       255,    255,    -1                 },
327 { "",       255,    255,    -1                 },
328 { "",       255,    255,    -1                 },
329 { "",       255,    255,    -1                 },
330 { "",       255,    255,    -1                 },
331 { "",       255,    255,    -1                 },
332 { "",       255,    255,    -1                 },
333 { "",       255,    255,    -1                 },
334 { "",       255,    255,    -1                 },
335 { "",       255,    255,    -1                 },
336 { "",       255,    255,    -1                 },
337 { "",       255,    255,    -1                 },
338 { "",       255,    255,    -1                 },
339 { "",       255,    255,    -1                 },
340 { "",       255,    255,    -1                 },
341 { "",       255,    255,    -1                 },
342 { "",       255,    255,    -1                 },
343 { "",       255,    255,    -1                 },
344 { "",       255,    255,    -1                 },
345 { "",       255,    255,    -1                 },
346 { "",       255,    255,    -1                 },
347 { "",       255,    255,    -1                 },
348 { "",       255,    255,    -1                 },
349 { "",       255,    255,    -1                 },
350 };
351
352 char *key_text[256];
353
354 void key_buid_key_text(void)
355 {
356 }
357
358 unsigned char key_to_ascii(int keycode )
359 {
360         int shifted;
361
362         shifted = keycode & KEY_SHIFTED;
363         keycode &= 0xFF;
364
365         if (shifted)
366                 return key_properties[keycode].shifted_ascii_value;
367         else
368                 return key_properties[keycode].ascii_value;
369 }
370
371 void key_handler(SDL_KeyboardEvent *event)
372 {
373         ubyte state;
374         int i, keycode, event_key, key_state;
375         Key_info *key;
376         unsigned char temp;
377
378         event_key = event->keysym.sym;
379
380         key_state = (event->state == SDL_PRESSED); //  !(wInfo & KF_UP);
381         //=====================================================
382         //Here a translation from win keycodes to mac keycodes!
383         //=====================================================
384
385         for (i = 255; i >= 0; i--) {
386
387                 keycode = i;
388                 key = &(key_data.keys[keycode]);
389                 if (key_properties[i].sym == event_key)
390                         state = key_state;
391                 else
392                         state = key->last_state;
393                         
394                 if ( key->last_state == state ) {
395                         if (state) {
396                                 key->counter++;
397                                 keyd_last_pressed = keycode;
398                                 keyd_time_when_last_pressed = timer_get_fixed_seconds();
399                         }
400                 } else {
401                         if (state)      {
402                                 keyd_last_pressed = keycode;
403                                 keyd_pressed[keycode] = 1;
404                                 key->downcount += state;
405                                 key->state = 1;
406                                 key->timewentdown = keyd_time_when_last_pressed = timer_get_fixed_seconds();
407                                 key->counter++;
408                         } else {        
409                                 keyd_pressed[keycode] = 0;
410                                 keyd_last_released = keycode;
411                                 key->upcount += key->state;
412                                 key->state = 0;
413                                 key->counter = 0;
414                                 key->timehelddown += timer_get_fixed_seconds() - key->timewentdown;
415                         }
416                 }
417                 if ( (state && !key->last_state) || (state && key->last_state && (key->counter > 30) && (key->counter & 0x01)) ) {
418                         if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT])
419                                 keycode |= KEY_SHIFTED;
420                         if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT])
421                                 keycode |= KEY_ALTED;
422                         if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL])
423                                 keycode |= KEY_CTRLED;
424                         if ( keyd_pressed[KEY_DELETE] )
425                                 keycode |= KEY_DEBUGGED;
426                         temp = key_data.keytail+1;
427                         if ( temp >= KEY_BUFFER_SIZE ) temp=0;
428                         if (temp!=key_data.keyhead)     {
429                                 key_data.keybuffer[key_data.keytail] = keycode;
430                                 key_data.time_pressed[key_data.keytail] = keyd_time_when_last_pressed;
431                                 key_data.keytail = temp;
432                         }
433                 }
434                 key->last_state = state;
435         }
436 }
437
438 void key_close()
439 {
440  Installed = 0;
441 }
442
443 void key_init()
444 {
445   int i;
446   
447   if (Installed) return;
448
449   Installed=1;
450
451   keyd_time_when_last_pressed = timer_get_fixed_seconds();
452   keyd_buffer_type = 1;
453   keyd_repeat = 1;
454   
455   for(i=0; i<256; i++)
456      key_text[i] = key_properties[i].key_text;
457      
458   // Clear the keyboard array
459   key_flush();
460   atexit(key_close);
461 }
462
463 void key_flush()
464 {
465         int i;
466         fix curtime;
467
468         if (!Installed)
469                 key_init();
470
471         key_data.keyhead = key_data.keytail = 0;
472
473         //Clear the keyboard buffer
474         for (i=0; i<KEY_BUFFER_SIZE; i++ )      {
475                 key_data.keybuffer[i] = 0;
476                 key_data.time_pressed[i] = 0;
477         }
478
479 //use gettimeofday here:
480         curtime = timer_get_fixed_seconds();
481
482         for (i=0; i<256; i++ )  {
483                 keyd_pressed[i] = 0;
484                 key_data.keys[i].state = 1;
485                 key_data.keys[i].last_state = 0;
486                 key_data.keys[i].timewentdown = curtime;
487                 key_data.keys[i].downcount=0;
488                 key_data.keys[i].upcount=0;
489                 key_data.keys[i].timehelddown = 0;
490                 key_data.keys[i].counter = 0;
491         }
492 }
493
494 int add_one(int n)
495 {
496  n++;
497  if ( n >= KEY_BUFFER_SIZE ) n=0;
498  return n;
499 }
500
501 int key_checkch()
502 {
503         int is_one_waiting = 0;
504         event_poll();
505         if (key_data.keytail!=key_data.keyhead)
506                 is_one_waiting = 1;
507         return is_one_waiting;
508 }
509
510 int key_inkey()
511 {
512         int key = 0;
513         if (!Installed)
514                 key_init();
515         event_poll();
516         if (key_data.keytail!=key_data.keyhead) {
517                 key = key_data.keybuffer[key_data.keyhead];
518                 key_data.keyhead = add_one(key_data.keyhead);
519         }
520 //added 9/3/98 by Matt Mueller to free cpu time instead of hogging during menus and such
521         else d_delay(1);
522 //end addition - Matt Mueller
523              
524         return key;
525 }
526
527 int key_inkey_time(fix * time)
528 {
529         int key = 0;
530
531         if (!Installed)
532                 key_init();
533         event_poll();
534         if (key_data.keytail!=key_data.keyhead) {
535                 key = key_data.keybuffer[key_data.keyhead];
536                 *time = key_data.time_pressed[key_data.keyhead];
537                 key_data.keyhead = add_one(key_data.keyhead);
538         }
539         return key;
540 }
541
542 int key_peekkey()
543 {
544         int key = 0;
545         event_poll();
546         if (key_data.keytail!=key_data.keyhead)
547                 key = key_data.keybuffer[key_data.keyhead];
548
549         return key;
550 }
551
552 int key_getch()
553 {
554         int dummy=0;
555
556         if (!Installed)
557                 return 0;
558 //              return getch();
559
560         while (!key_checkch())
561                 dummy++;
562         return key_inkey();
563 }
564
565 unsigned int key_get_shift_status()
566 {
567         unsigned int shift_status = 0;
568
569         if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT] )
570                 shift_status |= KEY_SHIFTED;
571
572         if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
573                 shift_status |= KEY_ALTED;
574
575         if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL] )
576                 shift_status |= KEY_CTRLED;
577
578 #ifndef NDEBUG
579         if (keyd_pressed[KEY_DELETE])
580                 shift_status |=KEY_DEBUGGED;
581 #endif
582
583         return shift_status;
584 }
585
586 // Returns the number of seconds this key has been down since last call.
587 fix key_down_time(int scancode)
588 {
589         fix time_down, time;
590
591         event_poll();
592         if ((scancode<0)|| (scancode>255)) return 0;
593
594         if (!keyd_pressed[scancode]) {
595                 time_down = key_data.keys[scancode].timehelddown;
596                 key_data.keys[scancode].timehelddown = 0;
597         } else {
598                 time = timer_get_fixed_seconds();
599                 time_down = time - key_data.keys[scancode].timewentdown;
600                 key_data.keys[scancode].timewentdown = time;
601         }
602
603         return time_down;
604 }
605
606 unsigned int key_down_count(int scancode)
607 {
608         int n;
609         event_poll();
610         if ((scancode<0)|| (scancode>255)) return 0;
611
612         n = key_data.keys[scancode].downcount;
613         key_data.keys[scancode].downcount = 0;
614
615         return n;
616 }
617
618 unsigned int key_up_count(int scancode)
619 {
620         int n;
621         event_poll();
622         if ((scancode<0)|| (scancode>255)) return 0;
623
624         n = key_data.keys[scancode].upcount;
625         key_data.keys[scancode].upcount = 0;
626
627         return n;
628 }