Modifier keys pressed during initialization stick

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?–
CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/

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?

  • Silicon

John Silicon 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?

Version of SDL would be good to know too. If you (jimrandomh) are using
anything earlier than 1.2.8, try upgrading and see if that fixes it.> - Silicon


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

John Silicon 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.–
CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/

John Silicon 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.

If the bug is the result of using Net2 please let me know. Since I wrote
Net2 I like to fix its bugs :-). Though, since I do not have Windows 2k
I might need your cooperation to fix the problem.

Thanks
	Bob PendletonOn Fri, 2005-01-14 at 05:46 +0000, jimrandomh wrote:

jimrandomh wrote:

John Silicon 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
#include
using namespace std;

void print_key(SDL_keysym *key);

int main(int argc, char **argv)
{
SDL_Event ev;

cout << "SDL "<<SDL_MAJOR_VERSION<<"."<<SDL_MINOR_VERSION

<<"."<<SDL_PATCHLEVEL<<endl;

SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(640, 480, 32, 0);

while(SDL_WaitEvent(&ev))
switch (ev.type)
{
	case SDL_QUIT:
		SDL_Quit();
		exit(0);
		break;
		
	case SDL_KEYDOWN:
		print_key(&ev.key.keysym);
		break;
}

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.
http://calcrogue.jimrandomh.org/