John Silicon 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
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.
enter down (program starts)
Wait for window to appear
Under Windows 98, the output was correct:
left shift down
left shift up
Under Windows 2000 and under Windows XP, the output was:
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:
using namespace std;
void print_key(SDL_keysym *key);
int main(int argc, char **argv)
cout << "SDL "<<SDL_MAJOR_VERSION<<"."<<SDL_MINOR_VERSION
SDL_SetVideoMode(640, 480, 32, 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.