Problem when multiple arrow keys are held down

Greetings,

I am quite new to SDL (used to use GLUT before) so I hope this is not a
recurrent newbie topic.
Here’s the problem: using the arrow keys to move an object (move forward
and back, strafe left and right) I realized that when moving in diagonal
(for example, the UP and LEFT keys are held down) additional keypresses
(say, the space bar to shoot a gun) did not seem to get registered by SDL –
except for one diagonal (the UP+RIGHT one). note: keyrepeat was disabled.
By using letters (q,s,a,d) instead of the arrows, I do not encounter that
problem. Is this a known bug or will I have to go scrutinize my code again?
:slight_smile:
I have looked at the changelog for versions 1.2.5 and 1.2.6 (because I’m
currently using version 1.2.4) but didn’t see an entry related to this, but
I will still try and upgrade my SDL lib.

Thanks,
Terii

I don’t want to say anything stupid, but I think this
is neither a problem with your code nor a bug in SDL :
this is a know limitation of PCs… (can’t remember
the exact reason, must be due to the bios itself). I
remember having such troubles when playing Doom under
DOS :wink:
That’s why most FPS switched to w,s,a,d (z,s,q,d under
us french’s keyboards!), I guess…

Bye! Sandy/Moonlight

— terii a ?crit :>

Greetings,

I am quite new to SDL (used to use GLUT before) so I
hope this is not a
recurrent newbie topic.
Here’s the problem: using the arrow keys to move an
object (move forward
and back, strafe left and right) I realized that
when moving in diagonal
(for example, the UP and LEFT keys are held down)
additional keypresses
(say, the space bar to shoot a gun) did not seem to
get registered by SDL –
except for one diagonal (the UP+RIGHT one). note:
keyrepeat was disabled.
By using letters (q,s,a,d) instead of the arrows, I
do not encounter that
problem. Is this a known bug or will I have to go
scrutinize my code again?
:slight_smile:
I have looked at the changelog for versions 1.2.5
and 1.2.6 (because I’m
currently using version 1.2.4) but didn’t see an
entry related to this, but
I will still try and upgrade my SDL lib.

Thanks,
Terii


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

Anthony Portier a ?crit:

I don’t want to say anything stupid, but I think this
is neither a problem with your code nor a bug in SDL :
this is a know limitation of PCs… (can’t remember
the exact reason, must be due to the bios itself). I
remember having such troubles when playing Doom under
DOS :wink: That’s why most FPS switched to w,s,a,d (z,s,q,d under
us french’s keyboards!), I guess…

Bye! Sandy/Moonlight

It has to be that. I can’t believe I had not noticed that before (/me is
ashamed).
Thanks Moonlight :slight_smile:

I don’t think so. I certainly don’t experience this problem on my PC.

The PC’s keyboard controller detects when a key is pressed and when it is
released, but in the meantime it cannot tell what state they key is in, so it
is up to software to keep track. The keyboard software in the BIOS isn’t that
great, which is probably why nobody used it, even back in the days of DOS.

What your code should do (if it isn’t doing it already) is something like this
(taken from the SDL documentation):

/* Alien screen coordinates */
int alien_x=0, alien_y=0;
int alien_xvel=0, alien_yvel=0;
.
.
/* Initialise SDL and video modes and all that */
.
/* Main game loop */
/* Check for events */
while( SDL_PollEvent( &event ) ){
    switch( event.type ){
        /* Look for a keypress */
        case SDL_KEYDOWN:
            /* Check the SDLKey values and move change the coords */
            switch( event.key.keysym.sym ){
                case SDLK_LEFT:
                    alien_xvel = -1;
                    break;
                case SDLK_RIGHT:
                    alien_xvel =  1;
                    break;
                case SDLK_UP:
                    alien_yvel = -1;
                    break;
                case SDLK_DOWN:
                    alien_yvel =  1;
                    break;
                default:
                    break;
            }
            break;
        /* We must also use the SDL_KEYUP events to zero the x */
        /* and y velocity variables. But we must also be       */
        /* careful not to zero the velocities when we shouldn't*/
        case SDL_KEYUP:
            switch( event.key.keysym.sym ){
                case SDLK_LEFT:
                    /* We check to make sure the alien is moving */
                    /* to the left. If it is then we zero the    */
                    /* velocity. If the alien is moving to the   */
                    /* right then the right key is still press   */
                    /* so we don't tocuh the velocity            */
                    if( alien_xvel < 0 )
                        alien_xvel = 0;
                    break;
                case SDLK_RIGHT:
                    if( alien_xvel > 0 )
                        alien_xvel = 0;
                    break;
                case SDLK_UP:
                    if( alien_yvel < 0 )
                        alien_yvel = 0;
                    break;
                case SDLK_DOWN:
                    if( alien_yvel > 0 )
                        alien_yvel = 0;
                    break;
                default:
                    break;
            }
            break;
        
        default:
            break;
    }
}
.
.
/* Update the alien position */
alien_x += alien_xvel;
alien_y += alien_yvel;

The reason games started using the wsad setup is because it’s more
comfortable. In the days of Doom, you’d have your right hand on the arrow
keys, and your left on the rest. When aiming with the moust became the norm,
people would have to put their left hand on the arrow keys, which can get
uncomfortable after a while (depending on where you put your keyboard). This,
and because many players would immediately change the keyboard controls to it
anyway (once games started allowing you to change which keys did what), is
what drove game developers to start making the w, s, a, and d keys the
default. At least, that’s how I remember it.

-Sean RidenourOn Saturday 30 August 2003 4:35 am, terii wrote:

Anthony Portier a ?crit:

I don’t want to say anything stupid, but I think this
is neither a problem with your code nor a bug in SDL :
this is a know limitation of PCs… (can’t remember
the exact reason, must be due to the bios itself). I
remember having such troubles when playing Doom under
DOS :wink: That’s why most FPS switched to w,s,a,d (z,s,q,d under
us french’s keyboards!), I guess…

Bye! Sandy/Moonlight

It has to be that. I can’t believe I had not noticed that before (/me is
ashamed).
Thanks Moonlight :slight_smile:

Anthony Portier a ?crit:

I don’t want to say anything stupid, but I think this
is neither a problem with your code nor a bug in SDL :
this is a know limitation of PCs… (can’t remember
the exact reason, must be due to the bios itself). I
remember having such troubles when playing Doom under
DOS :wink: That’s why most FPS switched to w,s,a,d (z,s,q,d under
us french’s keyboards!), I guess…

Bye! Sandy/Moonlight

I don’t think so. I certainly don’t experience this problem on my PC.

The PC’s keyboard controller detects when a key is pressed and when it is
released, but in the meantime it cannot tell what state they key is in,
so it is up to software to keep track. The keyboard software in the BIOS
isn’t that great, which is probably why nobody used it, even back in the
days of DOS.

What your code should do (if it isn’t doing it already) is something like
this (taken from the SDL documentation):

> > The reason games started using the wsad setup is because it's more > comfortable. In the days of Doom, you'd have your right hand on the arrow > keys, and your left on the rest. When aiming with the moust became the > norm, people would have to put their left hand on the arrow keys, which > can get uncomfortable after a while (depending on where you put your > keyboard). This, and because many players would immediately change the > keyboard controls to it anyway (once games started allowing you to change > which keys did what), is what drove game developers to start making the > w, s, a, and d keys the default. At least, that's how I remember it. > > -Sean Ridenour >

Thanks for the answer, Sean.
I do manage the keyboard input in a way similar to the one in that example
code (except I deal with accelerations instead of velocities, but that is
irrelevant to the problem, I believe). I came to agree with Moonlight
because I could reproduce the “bug” in Half-Life today (pressing and
holding down the UP and LEFT keys to run in circles, and trying to jump
with the spacebar: it didn’t work).

See ya,
TeriiOn Sat, 30 Aug 2003 05:51:36 -0700, Sean Ridenour wrote:

On Saturday 30 August 2003 4:35 am, terii wrote:

Thanks for the answer, Sean.
I do manage the keyboard input in a way similar to the one in that example
code (except I deal with accelerations instead of velocities, but that is
irrelevant to the problem, I believe). I came to agree with Moonlight
because I could reproduce the “bug” in Half-Life today (pressing and
holding down the UP and LEFT keys to run in circles, and trying to jump
with the spacebar: it didn’t work).

Yes, this is a limitation of some keyboards. Unfortunately, the exact
combinations which are valid vary from keyboard to keyboard, and this
"bug" is frequently reported in just about every action game.

(technically it has to do with the way the keys are wired internally)

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi! This is something Atrix Wolfe wrote, a week ago, I think is related
to your
Problem.

— not mine… Atrix’s dixit------ not mine… Atrix’s dixit------
not mine… Atrix’s dixit—
Hey Bob,

if you enable unicode, it handles the modifier flags for you and gives
you just the char you are looking for.

http://sdldoc.csn.ul.ie/sdlenableunicode.php
http://sdldoc.csn.ul.ie/sdlenableunicode.php <— CHECK THIS OUT

int SDL_EnableUNICODE(int enable);

in my game i have both buffered text input (enter your name) and also
control input
(pressing left and up at the same time to move diagonaly).

What i do is enable unicode first off, then i watch for keydown events
and add the
keys (Event.key.keysym.unicode) to a queue. So, when i want buffered
input, as soon
as buffered input is started, i empty the queue and then have a loop
that processes
the keys from the queue into a text box as they come in (waiting for
return key,
button press etc) and when i dont want buffered input i just ignore the
queue and just
use SDL_GetKeyState to check for control keys.

Does this make any sense? I hope so :stuck_out_tongue:
Atrix
— not mine… Atrix’s dixit------ not mine… Atrix’s dixit------
not mine… Atrix’s dixit—

If it works, and you like it, send a thank you note to Atrix
(atrix2 at cox.net)

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.

mailto:sdl-admin at libsdl.org] On> -----Original Message-----

From: sdl-admin at libsdl.org [ <mailto:sdl-admin at libsdl.org>
Behalf Of Sam Lantinga
Sent: Saturday, August 30, 2003 2:30 PM
To: sdl at libsdl.org
Subject: Re: [SDL] problem when multiple arrow keys are held down

Thanks for the answer, Sean.
I do manage the keyboard input in a way similar to the one in that
example
code (except I deal with accelerations instead of
velocities, but that is
irrelevant to the problem, I believe). I came to agree with
Moonlight
because I could reproduce the “bug” in Half-Life today
(pressing and
holding down the UP and LEFT keys to run in circles, and
trying to jump
with the spacebar: it didn’t work).

Yes, this is a limitation of some keyboards. Unfortunately,
the exact combinations which are valid vary from keyboard to
keyboard, and this “bug” is frequently reported in just about
every action game.

(technically it has to do with the way the keys are wired internally)

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


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

http://www.sjbaker.org/steve/omniv/keyboards_are_evil.htmlOn Fri, Aug 29, 2003 at 03:43:50PM +0200, terii wrote:

I am quite new to SDL (used to use GLUT before) so I hope this is not a
recurrent newbie topic.
Here’s the problem: using the arrow keys to move an object (move forward
and back, strafe left and right) I realized that when moving in diagonal
(for example, the UP and LEFT keys are held down) additional keypresses
(say, the space bar to shoot a gun) did not seem to get registered by SDL


Glenn Maynard

“Glenn Maynard” <g_sdl at zewt.org> ha scritto nel messaggio
news:20030901010341.GA648 at zewt.org

http://www.sjbaker.org/steve/omniv/keyboards_are_evil.html

page not found … the server is down ???

bye

it comes up for me, very interesting read :P> ----- Original Message -----

From: goul_dukat@despammed.com (Goul_duKat)
To:
Sent: Sunday, August 31, 2003 9:09 PM
Subject: [SDL] Re: problem when multiple arrow keys are held down

“Glenn Maynard” <g_sdl at zewt.org> ha scritto nel messaggio
news:20030901010341.GA648 at zewt.org

http://www.sjbaker.org/steve/omniv/keyboards_are_evil.html

page not found … the server is down ???

bye


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

Hi! This is something Atrix Wolfe wrote, a week ago, I think is related
to your
Problem.

— not mine… Atrix’s dixit------ not mine… Atrix’s dixit------
not mine… Atrix’s dixit—
Hey Bob,

if you enable unicode, it handles the modifier flags for you and gives
you just the char you are looking for.

http://sdldoc.csn.ul.ie/sdlenableunicode.php
http://sdldoc.csn.ul.ie/sdlenableunicode.php <— CHECK THIS OUT

Hi Juan Ignacio, the problem lies at a lower level, as pointed out by Sam
(and thanks for the “keyboards are evil” link, Glenn). Besides, unicode
translation returns 0 for keys producing non-printable characters,
including the arrows and F1-F12 keys.

Thank you for the input, everybody :slight_smile:
TeriiOn Sun, 31 Aug 2003 01:44:10 -0300, Juan Ignacio Carniglia wrote:

Sam Lantinga wrote:

Thanks for the answer, Sean.
I do manage the keyboard input in a way similar to the one in that example
code (except I deal with accelerations instead of velocities, but that is
irrelevant to the problem, I believe). I came to agree with Moonlight
because I could reproduce the “bug” in Half-Life today (pressing and
holding down the UP and LEFT keys to run in circles, and trying to jump
with the spacebar: it didn’t work).

Yes, this is a limitation of some keyboards. Unfortunately, the exact
combinations which are valid vary from keyboard to keyboard, and this
"bug" is frequently reported in just about every action game.

(technically it has to do with the way the keys are wired internally)

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

but in most cases (all keybs I have tried) the rule is the following:
when the 3 keys pressed make 3 corners of a rectangle, the 3rd key is
not registered by the keyboard chip also pressing 3 contiguous keys in a
horizontal row doen’t register the 3rd. it’s due to the keyboard wiring
like sam said. some older keyboards (around <1993) even don’t have
diodes between keys-switches and so instead of ignoring the 3rd press,
they interpret it as a press of the button that is in the 4th corner of
the abstact rectangle (like pressing together D-G-T would produce E)…

e.g. you can get registered press like G-H-O but not G-H-N etc.
the IBM PC standart wasn’t intendet to supprort keyboard as a game
console. multiple keystrokes weren’t needed.

515

I don’t think so. I certainly don’t experience this problem on my PC.

The PC’s keyboard controller detects when a key is pressed and when it is
released, but in the meantime it cannot tell what state they key is in, so it

I also rather think that this must be related to hardware/BIOS issues, but
not to SDL nor the code, because I’ve noticed that problem on one machine
with our game (freedroid), where DOWN+RIGHT didn’t work, on other
machines however that problem did not occur.

Cheers,
ReinhardOn Sat, 30 Aug 2003, Sean Ridenour wrote:

Reinhard Prix wrote:>On Sat, 30 Aug 2003, Sean Ridenour wrote:

I don’t think so. I certainly don’t experience this problem on my PC.

The PC’s keyboard controller detects when a key is pressed and when it is
released, but in the meantime it cannot tell what state they key is in, so it

I also rather think that this must be related to hardware/BIOS issues, but
not to SDL nor the code, because I’ve noticed that problem on one machine
with our game (freedroid), where DOWN+RIGHT didn’t work, on other
machines however that problem did not occur.

Cheers,
Reinhard

Some interesting info about this problem here:
http://www.sjbaker.org/steve/omniv/keyboards_are_evil.html