SDL_KEYUP/DOWN events

I have some code which does the following:

bool KeyPress[SDLKey];
...
then inside the event loop:
case SDL_KEYDOWN:
    KeyPress[event.key.keysym.sym] = true;
    break;
case SDL_KEYUP:
    KeyPress[event.key.keysym.sym] = false;
    break;

then there is a function which checks if a key has been pressed since
last time user checked:

 bool temp = mKeyPress[key];
 mKeyPress[key] = false;
 return temp;

This all works just fine, but if the user is pressing the up key, then
presses the left key the program acts as if the up key was released.
When the up key is actually released it seems to act as if the left key
was now released. This behavior has been tested on Redhat 8.0 and
Windows XP and Windows 98.

This works with a variety of keys, but I’ve mainly tested with arrows as
that is what this portion of the program is doing.

AFAIK, this is because of how various keyboard controllers handle
keypresses. It has nothing to do with SDL itself.On Tue, 2002-12-03 at 22:46, James Turk wrote:

This all works just fine, but if the user is pressing the up key, then
presses the left key the program acts as if the up key was released.
When the up key is actually released it seems to act as if the left key
was now released. This behavior has been tested on Redhat 8.0 and
Windows XP and Windows 98.

This works with a variety of keys, but I’ve mainly tested with arrows as
that is what this portion of the program is doing.

This doesn’t happen to me, in Win2K, using the SDL.

Many keyboards can’t handle certain combinations of keys, but that
usually only happens with three or more keys, and typically what happens
is when too many keys are pressed, it looks (to the system) like all of
the pressed keys have been released, so that’s probably not what’s
happening here.

James, I’d suggest putting in some debug output in the event loop; print
something whenever a key_up or key_down event is registered to see what
the SDL is actually sending. (Of course, normally it’s better to step
through code with a debugger, but that doesn’t tend to work very well
when testing this type of code.)On Tue, Dec 03, 2002 at 11:11:39PM -0600, DrEvil wrote:

This all works just fine, but if the user is pressing the up key, then
presses the left key the program acts as if the up key was released.
When the up key is actually released it seems to act as if the left key
was now released. This behavior has been tested on Redhat 8.0 and
Windows XP and Windows 98.

This works with a variety of keys, but I’ve mainly tested with arrows as
that is what this portion of the program is doing.

AFAIK, this is because of how various keyboard controllers handle
keypresses. It has nothing to do with SDL itself.


Glenn Maynard

Thanks for your replies, but I found a much cleaner way to do what
I was trying to do.

The way the code works, which Is a bit more complicated than I got into 

here, was the source of the problem I believe. What I was trying to do
was better done with the time-based movement system already in place so
I’m not too worried about it anymore.

I had already put in test output code and the way it's reporting it 

looks like it is either the keypress combinations (I remember this from
ModeX and other old DOS programming) or it may just be the way
SDL_EnableKeyRepeat works (not suggesting a bug here, just saying I
originally thought it’d register a SDL_KEYUP before registering another
SDL_KEYDOWN).

      -James

Glenn Maynard wrote:> On Tue, Dec 03, 2002 at 11:11:39PM -0600, DrEvil wrote:

This all works just fine, but if the user is pressing the up key, then
presses the left key the program acts as if the up key was released.
When the up key is actually released it seems to act as if the left key
was now released. This behavior has been tested on Redhat 8.0 and
Windows XP and Windows 98.

This works with a variety of keys, but I’ve mainly tested with arrows as
that is what this portion of the program is doing.

AFAIK, this is because of how various keyboard controllers handle
keypresses. It has nothing to do with SDL itself.

This doesn’t happen to me, in Win2K, using the SDL.

Many keyboards can’t handle certain combinations of keys, but that
usually only happens with three or more keys, and typically what happens
is when too many keys are pressed, it looks (to the system) like all of
the pressed keys have been released, so that’s probably not what’s
happening here.

James, I’d suggest putting in some debug output in the event loop; print
something whenever a key_up or key_down event is registered to see what
the SDL is actually sending. (Of course, normally it’s better to step
through code with a debugger, but that doesn’t tend to work very well
when testing this type of code.)

man SDL_GetKeyState :-)On Tue, Dec 03, 2002 at 11:46:38PM -0500, James Turk wrote:

bool KeyPress[SDLKey];

then inside the event loop:
case SDL_KEYDOWN:
KeyPress[event.key.keysym.sym] = true;
break;
case SDL_KEYUP:
KeyPress[event.key.keysym.sym] = false;
break;


http://decopter.sf.net - free unrealistic helicopter simulator