[SDL] Re: Modifier keys pressed during initialization stick

jimrandomh usenetNOSPAM at jimrandomh.org
Fri Jan 14 18:01:51 PST 2005

jimrandomh <usenetNOSPAM at jimrandomh.org> wrote:
> John Silicon <jsilicon at earthlink.net> wrote:
>> jimrandomh wrote:
>>>If a modifier key (ctrl, alt, shift, or meta) is held down while
>>>my program starts, but released during initialization, SDL thinks
>>>it's still held. In particular, I use "ctrl+F5" to start my
>>>program from an IDE, so keypresses I get have an extraneous ctrl+
>>>modifier on them until I press and release ctrl.
>>>This isn't a big problem, but it appears to be a bug and a fix or 
>>>workaround would be nice. Is this known?
>> I can not duplicate this, on my system -- what compiler (IDE, too,
>> if separate) & OS (if *nix, what kernel version?) are you seeing
>> this behavior? 
> Visual Studio 6, Windows 2000. I'm also using Net2, which, come to
> think of it, does some funky stuff to the event queue which could
> be related. I'll put together a reduced test case (and see if said
> test case requires net2) tomorrow.

>From further testing:
- It is not caused by net2
- It does not depend on SDL version
- It *is* OS dependent

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.

Here is my test program:

#include "SDL.h"
#include <iostream>
#include <string>
using namespace std;

void print_key(SDL_keysym *key);

int main(int argc, char **argv)
	SDL_Event ev;
	SDL_SetVideoMode(640, 480, 32, 0);
	switch (ev.type)
		case SDL_QUIT:
	return 0;

void print_key(SDL_keysym *key)
	string keyname = SDL_GetKeyName(key->sym);
	if(key->mod & KMOD_SHIFT) keyname = "shift-"+keyname;
	if(key->mod & KMOD_CTRL ) keyname = "ctrl-" +keyname;
	if(key->mod & KMOD_ALT  ) keyname = "alt-"  +keyname;
	if(key->mod & KMOD_META ) keyname = "meta-" +keyname;
	cout << keyname.c_str() << endl;

CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.

More information about the SDL mailing list