Date: Sat, 15 Jan 2005 02:01:51 +0000 (UTC)

From: jimrandomh
Subject: [SDL] Re: Modifier keys pressed during initialization stick

I wrote a simple test program which initializes SDL, prints the SDL
version number, then prints any keydown and keyup events with their
modifiers. (Source code below). Compilation was done using Visual
Studio 6, release mode.

My test sequence was:
Start a command prompt. Type the name of the test program.
shift down
enter down (program starts)
Wait for window to appear
enter up
shift up
spacebar down
spacebar up

Under Windows 98, the output was correct:
SDL 1.2.8
left shift down
shift-return down
shift-return up
left shift up
space down
space up

Under Windows 2000 and under Windows XP, the output was:
SDL 1.2.8
shift-space down
shift-space up

Since shift was not held at the time space was pressed, this is
incorrect. Similar results were observed with launching in different
ways (including double-clicking in Windows Explorer), so it does not
depend on the launching terminal.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401285
This commit is contained in:
Sam Lantinga 2006-01-29 07:57:13 +00:00
parent c76025809e
commit ee646e66c0
3 changed files with 23 additions and 14 deletions

View file

@ -506,6 +506,9 @@ printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym),
/* Drop events that don't change state */ /* Drop events that don't change state */
if ( SDL_KeyState[keysym->sym] == state ) { if ( SDL_KeyState[keysym->sym] == state ) {
#if 0
printf("Event didn't change state - dropped!\n");
#endif
return(0); return(0);
} }

View file

@ -214,21 +214,27 @@ static void WIN_GetKeyboardState(void)
if ( GetKeyboardState(keyboard) ) { if ( GetKeyboardState(keyboard) ) {
if ( keyboard[VK_LSHIFT] & 0x80) { if ( keyboard[VK_LSHIFT] & 0x80) {
state |= KMOD_LSHIFT; state |= KMOD_LSHIFT;
kstate[SDLK_LSHIFT] = SDL_PRESSED;
} }
if ( keyboard[VK_RSHIFT] & 0x80) { if ( keyboard[VK_RSHIFT] & 0x80) {
state |= KMOD_RSHIFT; state |= KMOD_RSHIFT;
kstate[SDLK_RSHIFT] = SDL_PRESSED;
} }
if ( keyboard[VK_LCONTROL] & 0x80) { if ( keyboard[VK_LCONTROL] & 0x80) {
state |= KMOD_LCTRL; state |= KMOD_LCTRL;
kstate[SDLK_LCTRL] = SDL_PRESSED;
} }
if ( keyboard[VK_RCONTROL] & 0x80) { if ( keyboard[VK_RCONTROL] & 0x80) {
state |= KMOD_RCTRL; state |= KMOD_RCTRL;
kstate[SDLK_RCTRL] = SDL_PRESSED;
} }
if ( keyboard[VK_LMENU] & 0x80) { if ( keyboard[VK_LMENU] & 0x80) {
state |= KMOD_LALT; state |= KMOD_LALT;
kstate[SDLK_LALT] = SDL_PRESSED;
} }
if ( keyboard[VK_RMENU] & 0x80) { if ( keyboard[VK_RMENU] & 0x80) {
state |= KMOD_RALT; state |= KMOD_RALT;
kstate[SDLK_RALT] = SDL_PRESSED;
} }
if ( keyboard[VK_NUMLOCK] & 0x01) { if ( keyboard[VK_NUMLOCK] & 0x01) {
state |= KMOD_NUM; state |= KMOD_NUM;

View file

@ -49,7 +49,6 @@ static char rcsid =
/* The translation table from a Microsoft VK keysym to a SDL keysym */ /* The translation table from a Microsoft VK keysym to a SDL keysym */
static SDLKey VK_keymap[SDLK_LAST]; static SDLKey VK_keymap[SDLK_LAST];
static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed); static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed);
static BOOL prev_shiftstates[2];
/* Masks for processing the windows KEYDOWN and KEYUP messages */ /* Masks for processing the windows KEYDOWN and KEYUP messages */
#define REPEATED_KEYMASK (1<<30) #define REPEATED_KEYMASK (1<<30)
@ -117,14 +116,16 @@ LONG
break; break;
case VK_SHIFT: case VK_SHIFT:
/* EXTENDED trick doesn't work here */ /* EXTENDED trick doesn't work here */
if (!prev_shiftstates[0] && (GetKeyState(VK_LSHIFT) & 0x8000)) { {
Uint8 *state = SDL_GetKeyState(NULL);
if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) {
wParam = VK_LSHIFT; wParam = VK_LSHIFT;
prev_shiftstates[0] = TRUE; } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) {
} else if (!prev_shiftstates[1] && (GetKeyState(VK_RSHIFT) & 0x8000)) {
wParam = VK_RSHIFT; wParam = VK_RSHIFT;
prev_shiftstates[1] = TRUE;
} else { } else {
/* Huh? */ /* Probably a key repeat */
return(0);
}
} }
break; break;
case VK_MENU: case VK_MENU:
@ -178,14 +179,16 @@ LONG
break; break;
case VK_SHIFT: case VK_SHIFT:
/* EXTENDED trick doesn't work here */ /* EXTENDED trick doesn't work here */
if (prev_shiftstates[0] && !(GetKeyState(VK_LSHIFT) & 0x8000)) { {
Uint8 *state = SDL_GetKeyState(NULL);
if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
wParam = VK_LSHIFT; wParam = VK_LSHIFT;
prev_shiftstates[0] = FALSE; } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
} else if (prev_shiftstates[1] && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
wParam = VK_RSHIFT; wParam = VK_RSHIFT;
prev_shiftstates[1] = FALSE;
} else { } else {
/* Huh? */ /* Probably a key repeat */
return(0);
}
} }
break; break;
case VK_MENU: case VK_MENU:
@ -372,9 +375,6 @@ void DIB_InitOSKeymap(_THIS)
VK_keymap[VK_SNAPSHOT] = SDLK_PRINT; VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
VK_keymap[VK_CANCEL] = SDLK_BREAK; VK_keymap[VK_CANCEL] = SDLK_BREAK;
VK_keymap[VK_APPS] = SDLK_MENU; VK_keymap[VK_APPS] = SDLK_MENU;
prev_shiftstates[0] = FALSE;
prev_shiftstates[1] = FALSE;
} }
static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed) static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed)