SDL_GetKeyState(0) and WASD

Hello,

If I have:

Code:
Uint8 *keystate = SDL_GetKeyState(0);
if (keystate[SDLK_w]) printf(“Up: Pressed.\n”);
else printf(“Up: released.\n”);
if (keystate[SDLK_s]) printf(“Down: Pressed.\n”);
else printf(“Down: released.\n”);
if (keystate[SDLK_a]) printf(“Left: Pressed.\n”);
else printf(“Left: released.\n”);
if (keystate[SDLK_d]) printf(“Right: Pressed.\n”);
else printf(“Right: released.\n”);

If I press W, A and S I’ll get the output:

Code:
Up: Pressed.
Down: Pressed.
Left: Pressed.
Right: released.

But then if I also press D, keeping W, A and S pressed it’ll output:

Code:
Up: released.
Down: released.
Left: released.
Right: released.

The same happens with any combination of these keys. The final key causes SDL_GetKeyState(0) to register them as released.

I get the same behaviour when evaluating SDL_KeyboardEvent.

Is it merely because SDL can’t handle more than 4 simultaneous key presses? Or is it something to do with my keyboard/OS?

NB: Some combinations of keys seem to allow more than 4, but not many more. Like 5 or 6 simultaneous keys.

Linux
SDL compile-time version 1.2.14
SDL runtime version 1.2.14

Thanks in advance :slight_smile:

[…]

But then if I also press D, keeping W, A and S pressed it’ll output:

Code:
Up: released.
Down: released.
Left: released.
Right: released.
[…]

Ghosting. It’s a hardware problem caused by “cheap” keyboards implementing
scan matrixes without diodes. This happens, in various variations, on all
keyboards, except for a few of the most extreme gaming keyboards.

Nothing much you can do about it, apart from allowing the user to pick keys
that happen to work on his/her keyboard. Arrow keys are usually safe, but you
can’t even bet on that.On Wednesday 07 December 2011, at 17.45.54, “richyelbag” <richard.simkins at gmail.com> wrote:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’

**
Hello,

If I have:

Code:

Uint8 *keystate = SDL_GetKeyState(0);
if (keystate[SDLK_w]) printf(“Up: Pressed.\n”);
else printf(“Up: released.\n”);
if (keystate[SDLK_s]) printf(“Down: Pressed.\n”);
else printf(“Down: released.\n”);
if (keystate[SDLK_a]) printf(“Left: Pressed.\n”);
else printf(“Left: released.\n”);
if (keystate[SDLK_d]) printf(“Right: Pressed.\n”);
else printf(“Right: released.\n”);

If I press W, A and S I’ll get the output:

Code:

Up: Pressed.
Down: Pressed.
Left: Pressed.
Right: released.

But then if I also press D, keeping W, A and S pressed it’ll output:

Code:

Up: released.
Down: released.
Left: released.
Right: released.

The same happens with any combination of these keys. The final key causes
SDL_GetKeyState(0) to register them as released.

I get the same behaviour when evaluating SDL_KeyboardEvent.

Is it merely because SDL can’t handle more than 4 simultaneous key
presses? Or is it something to do with my keyboard/OS?

Limitation of the keyboard hardware itself. Keyboards aren’t designed to
allow a huge number of buttons to be simultaneously held.

NB: Some combinations of keys seem to allow more than 4, but not many
more. Like 5 or 6 simultaneous keys.

LinuxOn Wed, Dec 7, 2011 at 10:45 AM, richyelbag <richard.simkins at gmail.com>wrote:

SDL compile-time version 1.2.14
SDL runtime version 1.2.14

Thanks in advance [image: Smile]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello !

I do not know what kind of software you are working on,
but in a game you typically do not need Left && Right or
Up && Down at the same time.

CU

Cheers Dave, Patrick,

Yes, I was afraid that was the answer :slight_smile:

Keyboards are Evil:
http://www.sjbaker.org/wiki/index.php?title=Keyboards_Are_Evil

SA

Cheers SA,

The keyboard matrix is a useful bit of info.

@Torsten

I wanted to press A then D and W then S without letting go of the keys and have the sprite move correctly. But you’re right, it isn’t really necessary.

Try buying a cheap USB gamepad or a 360 controller. You might recommend
use of such in a game you make. Nobody will buy an NKRO keyboard when your
game is better with it, but gamepads are a little easier to come by and are
more widely useful.

Jonny DOn Wed, Dec 7, 2011 at 2:08 PM, richyelbag <richard.simkins at gmail.com>wrote:

**
Cheers SA,

The keyboard matrix is a useful bit of info.

@Torsten

I wanted to press A then D and W then S without letting go of the keys and
have the sprite move correctly. But you’re right, it isn’t really necessary.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Heh! This brings memories, almost 20 years ago.

Back then Archon, Barbarian, Sopwith and Star Control were my favourite
games, and StarCon came with DOS utility to check which keys can be
pressed at the same time and don’t block others.

When playing against someone else it was on the same keyboard, one would
use WASDQE, the other one the pad-keys(845679 or Insert/Delete).

I do remmember that certain IBM keyboards were able to get like 10-12
keys pressed at the same time and working fine…

Oh, I miss the days :)On 12/7/2011 8:45 AM, richyelbag wrote:

Hello,

If I have:

Code:

Uint8 *keystate = SDL_GetKeyState(0);
if (keystate[SDLK_w]) printf(“Up: Pressed.\n”);
else printf(“Up: released.\n”);
if (keystate[SDLK_s]) printf(“Down: Pressed.\n”);
else printf(“Down: released.\n”);
if (keystate[SDLK_a]) printf(“Left: Pressed.\n”);
else printf(“Left: released.\n”);
if (keystate[SDLK_d]) printf(“Right: Pressed.\n”);
else printf(“Right: released.\n”);

If I press W, A and S I’ll get the output:

Code:

Up: Pressed.
Down: Pressed.
Left: Pressed.
Right: released.

But then if I also press D, keeping W, A and S pressed it’ll output:

Code:

Up: released.
Down: released.
Left: released.
Right: released.

The same happens with any combination of these keys. The final key
causes SDL_GetKeyState(0) to register them as released.

I get the same behaviour when evaluating SDL_KeyboardEvent.

Is it merely because SDL can’t handle more than 4 simultaneous key
presses? Or is it something to do with my keyboard/OS?

NB: Some combinations of keys seem to allow more than 4, but not many
more. Like 5 or 6 simultaneous keys.

Linux
SDL compile-time version 1.2.14
SDL runtime version 1.2.14

Thanks in advance Smile


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hallo !

Heh! This brings memories, almost 20 years ago.

Back then Archon, Barbarian, Sopwith and Star Control were my favourite games, and StarCon
came with DOS utility to check which keys can be pressed at the same time and don’t block others.

Alley Cat, Bushido, Digger :slight_smile:

CU