comparison src/video/ataricommon/SDL_ikbdevents.c @ 1082:48436ffdf677

Avoid generating multiple key press/release messages for the same key
author Patrice Mandin <patmandin@gmail.com>
date Wed, 29 Jun 2005 20:32:46 +0000
parents b8d311d90021
children a55ac374271c
comparison
equal deleted inserted replaced
1081:369dcdb52d70 1082:48436ffdf677
52 K_CAPSLOCK, 52 K_CAPSLOCK,
53 K_CLRHOME, 53 K_CLRHOME,
54 K_INSERT 54 K_INSERT
55 }; 55 };
56 56
57 /* To save state of keyboard */
58 #define ATARIBIOS_MAXKEYS 128 57 #define ATARIBIOS_MAXKEYS 128
59 58
60 static unsigned char ikbd_previouskeyboard[ATARIBIOS_MAXKEYS]; 59 #define KEY_PRESSED 0xff
61 static Uint16 atari_prevmouseb; /* buttons */ 60 #define KEY_UNDEFINED 0x80
61 #define KEY_RELEASED 0x00
62 62
63 /* The translation tables from a console scancode to a SDL keysym */ 63 /* The translation tables from a console scancode to a SDL keysym */
64 #define KT_NOCHANGE -1 64 #define KT_NOCHANGE -1
65 65
66 enum { 66 enum {
67 KT_UNSHIFT=0, 67 KT_UNSHIFT=0,
68 KT_SHIFT=1, 68 KT_SHIFT=1,
69 KT_CAPS=2 69 KT_CAPS=2
70 }; 70 };
71 71
72 static int caps_state; 72 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
73 static int caps_state; /* caps lock state */
73 _KEYTAB *curtables; 74 _KEYTAB *curtables;
74 static unsigned char *tab_unshift, *tab_shift, *tab_caps; 75 static unsigned char *tab_unshift, *tab_shift, *tab_caps;
75 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 76 static SDLKey keymap[ATARIBIOS_MAXKEYS];
76 77
77 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym); 78 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym);
78 79
79 void AtariIkbd_InitOSKeymap(_THIS) 80 void AtariIkbd_InitOSKeymap(_THIS)
80 { 81 {
81 int i; 82 int i;
82 83
83 memset(SDL_AtariIkbd_keyboard, 0, ATARIBIOS_MAXKEYS); 84 memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
84 memset(ikbd_previouskeyboard, 0, ATARIBIOS_MAXKEYS);
85 85
86 /* Initialize keymap */ 86 /* Initialize keymap */
87 for ( i=0; i<sizeof(keymap); i++ ) 87 for ( i=0; i<sizeof(keymap); i++ )
88 keymap[i] = SDLK_UNKNOWN; 88 keymap[i] = SDLK_UNKNOWN;
89 89
150 int specialkeys; 150 int specialkeys;
151 151
152 /*--- Send keyboard events ---*/ 152 /*--- Send keyboard events ---*/
153 153
154 /* Update caps lock state */ 154 /* Update caps lock state */
155 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] && !ikbd_previouskeyboard[SCANCODE_CAPSLOCK]) 155 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK]==KEY_PRESSED) {
156 caps_state ^= 1; 156 caps_state ^= 1;
157 }
157 158
158 /* Choose the translation table */ 159 /* Choose the translation table */
159 specialkeys=KT_UNSHIFT; 160 specialkeys=KT_UNSHIFT;
160 if (SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] || SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]) 161 if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT]==KEY_PRESSED)
162 || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]==KEY_PRESSED))
163 {
161 specialkeys = KT_SHIFT; 164 specialkeys = KT_SHIFT;
162 if (caps_state) 165 }
166 if (caps_state) {
163 specialkeys = KT_CAPS; 167 specialkeys = KT_CAPS;
168 }
164 169
165 /* Now generate events */ 170 /* Now generate events */
166 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 171 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
167 /* Key pressed ? */ 172 /* Key pressed ? */
168 if (SDL_AtariIkbd_keyboard[i] && !ikbd_previouskeyboard[i]) 173 if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) {
169 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym)); 174 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym));
175 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
176 }
170 177
171 /* Key unpressed ? */ 178 /* Key released ? */
172 if (ikbd_previouskeyboard[i] && !SDL_AtariIkbd_keyboard[i]) 179 if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) {
173 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym)); 180 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym));
174 } 181 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
175 182 }
176 /* Will be previous table */ 183 }
177 memcpy(ikbd_previouskeyboard, SDL_AtariIkbd_keyboard, ATARIBIOS_MAXKEYS);
178 184
179 /*--- Send mouse events ---*/ 185 /*--- Send mouse events ---*/
180 186
181 /* Mouse motion ? */ 187 /* Mouse motion ? */
182 if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) { 188 if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) {
236 242
237 void AtariIkbd_ShutdownEvents(void) 243 void AtariIkbd_ShutdownEvents(void)
238 { 244 {
239 Supexec(SDL_AtariIkbdUninstall); 245 Supexec(SDL_AtariIkbdUninstall);
240 } 246 }
241