SDL_GetKeyState() and Uint?

Hi,

I’m using the SDL_GetKeyState() in a bomberman like (another one… but
it’s just for me and my friends which like drink beers each time they
loose…) anyway, I’m using it and I’m really disapointed as it returns
a Uint8*, and so the state of the keypad and the arrows are not provided
with this returns… so instead of Uin8* I wonder if this function
couldn’t return a Uint16* which would be much convenient…

I looked to the SDL sources and I think it woundln’t change so many
things…

Bye
Lawouach

I’m using the SDL_GetKeyState() in a bomberman like (another one… but
it’s just for me and my friends which like drink beers each time they
loose…) anyway, I’m using it and I’m really disapointed as it returns
a Uint8*, and so the state of the keypad and the arrows are not provided
with this returns… so instead of Uin8* I wonder if this function
couldn’t return a Uint16* which would be much convenient…

the key state vector is indexed by key sym number (SDLK_foo), not
by ascii or unicode

to anticipate your unasked question, don’t forget to pump events

Mattias Engdeg?rd wrote:

I’m using the SDL_GetKeyState() in a bomberman like (another one… but
it’s just for me and my friends which like drink beers each time they
loose…) anyway, I’m using it and I’m really disapointed as it returns
a Uint8*, and so the state of the keypad and the arrows are not provided
with this returns… so instead of Uin8* I wonder if this function
couldn’t return a Uint16* which would be much convenient…

the key state vector is indexed by key sym number (SDLK_foo), not
by ascii or unicode

to anticipate your unasked question, don’t forget to pump events

I’m neither a fool nor a stupid guy ! :confused:

I know that this function returns keysym number but just look at the
SDL_keysym.h and you’ll see that lots of keysym are bigger that 255 and
can’t be stored in a Uint8 array… so lots of keys aren’t return within
this function… moreover I put that fukin’ (sqz) function into the main
event loop so the the call to SDL_PumpEvent() is done…

Bye
Lawouach

I’m neither a fool nor a stupid guy ! :confused:

But you didn’t read the docs, did you.

</quote doc>
Uint8 *SDL_GetKeyState(int *numkeys);

Gets a snapshot of the current keyboard state. The current state is return
as a pointer to an array, the size of this array is stored in numkeys. The
array is indexed by the SDLK_* symbols. A value of 1 means the key is
pressed and a value of 0 means its not.
</quote doc>

So the array can have values that vary between 0 and 1. I don’t think you
need a Uint16 to store a 0 or a 1, do you?

</hint mode>
Uint8 *keystate = SDL_GetKeyState(NULL);
// check for the keypad ‘up’ key
if (keystate[SDLK_KP8])
{
// key is pressed
}
</hint mode>

[snip]
this function… moreover I put that fukin’ (sqz) function
[snip]

Another hint: try to be a little more friendly when you’re trying to ask
something. Refering to free & cool software like SDL, as “fuckin whatever”,
won’t increase the chances someone replies to your question…> -----Original Message-----

From: Sylvain.Hellegouarch

I know that this function returns keysym number but just look at the
SDL_keysym.h and you’ll see that lots of keysym are bigger that 255 and
can’t be stored in a Uint8 array… so lots of keys aren’t return within
this function… moreover I put that fukin’ (sqz) function into the main
event loop so the the call to SDL_PumpEvent() is done…

rtfm. SDL_GetKeyState() returns a pointer to a vector indexed by
keysym where each element is 1 if the key is pressed, 0 if not
i.e.

Uint8 *keystate = SDL_GetKeyState();
if(keystate[SDLK_RIGHT])
move_to_the_right();

note that you don’t have to use SDL_GetKeyState() — you can look at the
keypress/release events and keep track of which keys are pressed yourself

I’m neither a fool nor a stupid guy ! :confused:

we don’t think you are, but even clever people can misunderstand things

Dominique Biesmans wrote:

I’m neither a fool nor a stupid guy ! :confused:

But you didn’t read the docs, did you.

</quote doc>
Uint8 *SDL_GetKeyState(int *numkeys);

Gets a snapshot of the current keyboard state. The current state is return
as a pointer to an array, the size of this array is stored in numkeys. The
array is indexed by the SDLK_* symbols. A value of 1 means the key is
pressed and a value of 0 means its not.
</quote doc>

So the array can have values that vary between 0 and 1. I don’t think you
need a Uint16 to store a 0 or a 1, do you?

</hint mode>
Uint8 *keystate = SDL_GetKeyState(NULL);
// check for the keypad ‘up’ key
if (keystate[SDLK_KP8])
{
// key is pressed
}
</hint mode>

[snip]
this function… moreover I put that fukin’ (sqz) function
[snip]

Another hint: try to be a little more friendly when you’re trying to ask
something. Refering to free & cool software like SDL, as “fuckin whatever”,
won’t increase the chances someone replies to your question…

Thanks for being cool with me and really sorry to be little nervous, I
didn’t want to be so agressive

Bye guys
Lawouach> > -----Original Message-----

From: Sylvain.Hellegouarch

Is that a very good idea, actually?

I’m thinking about things like the application losing focus and thus missing
some up/down events - if SDL was to do anything clever about that, it would
also have to make sure to mirror the clever adjustments in the keystate array
by “emulating” the corresponding key events, or these two methods would
produce different results…

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Tuesday 20 February 2001 11:38, Mattias Engdeg?rd wrote:

note that you don’t have to use SDL_GetKeyState() — you can look at the
keypress/release events and keep track of which keys are pressed yourself

The array SDL_GetKeyState returns is kept updated internally withing the
SDL_PrivateKeyboard function. SDL_PrivateKeyboard is also responsible
for posting SDL keyboard events at the same time, so the information in
the SDL_GetKeyState array the any information obtained from SDL keyboard
events is always identical.On Tue, Feb 20, 2001 at 07:56:15PM +0100, David Olofson wrote:

On Tuesday 20 February 2001 11:38, Mattias Engdeg?rd wrote:

note that you don’t have to use SDL_GetKeyState() — you can look at the
keypress/release events and keep track of which keys are pressed yourself

Is that a very good idea, actually?

I’m thinking about things like the application losing focus and thus missing
some up/down events - if SDL was to do anything clever about that, it would
also have to make sure to mirror the clever adjustments in the keystate array
by “emulating” the corresponding key events, or these two methods would
produce different results…


Martin

Bother! said Pooh, as Will Riker attempted to mate with him.

Is that behavior guaranteed in the API spec? :slight_smile:

(I wasn’t expecting that it would work any other way; just pointing out that
it’s theoretically possible that it could change some time for some reason.)

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 01:50, Martin J Donlon wrote:

On Tue, Feb 20, 2001 at 07:56:15PM +0100, David Olofson wrote:

On Tuesday 20 February 2001 11:38, Mattias Engdeg?rd wrote:

note that you don’t have to use SDL_GetKeyState() — you can look at
the keypress/release events and keep track of which keys are pressed
yourself

Is that a very good idea, actually?

I’m thinking about things like the application losing focus and thus
missing some up/down events - if SDL was to do anything clever about
that, it would also have to make sure to mirror the clever adjustments in
the keystate array by “emulating” the corresponding key events, or these
two methods would produce different results…

The array SDL_GetKeyState returns is kept updated internally withing the
SDL_PrivateKeyboard function. SDL_PrivateKeyboard is also responsible
for posting SDL keyboard events at the same time, so the information in
the SDL_GetKeyState array the any information obtained from SDL keyboard
events is always identical.

The array SDL_GetKeyState returns is kept updated internally withing the
SDL_PrivateKeyboard function. SDL_PrivateKeyboard is also responsible
for posting SDL keyboard events at the same time, so the information in
the SDL_GetKeyState array the any information obtained from SDL keyboard
events is always identical.

Is that behavior guaranteed in the API spec? :slight_smile:
Spec?

(I wasn’t expecting that it would work any other way; just pointing out that
it’s theoretically possible that it could change some time for some reason.)
Well any other way would be broken.
However, I am curious how SDL handles key releases when the app doesn’t
have focus. Sam?On Wed, Feb 21, 2001 at 02:53:34AM +0100, David Olofson wrote:


Martin

Bother! said Pooh, as he turned into a bat.

However, I am curious how SDL handles key releases when the app doesn’t
have focus. Sam?

When the app loses focus, all keys are released.
When the app gains focus, the current key state is queried if possible,
and the keys that are still down generate key press events. If it’s not
possible to detect the current key state, the keys are left released, and
the next time they are pressed the keyboard state is in sync again.

It’s not necesarily the best way to do things, but it’s the cleanest
portable way I could think of.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Well, if there is anything more than the man page and the code comments…

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 15:38, Martin J Donlon wrote:

On Wed, Feb 21, 2001 at 02:53:34AM +0100, David Olofson wrote:

The array SDL_GetKeyState returns is kept updated internally withing
the SDL_PrivateKeyboard function. SDL_PrivateKeyboard is also
responsible for posting SDL keyboard events at the same time, so the
information in the SDL_GetKeyState array the any information obtained
from SDL keyboard events is always identical.

Is that behavior guaranteed in the API spec? :slight_smile:

Spec?

Well, if there is anything more than the man page and the code comments…

There isn’t a formal spec. SDL sort of evolved. If someone has enough time,
I’ll be happy to help them whip up one based on the SDL documentation project.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hmmm…I was gonna say that would be a bad idea since I’m sure there are
still many areas in the bowels of SDLdoc that are just plain wrong.
However, if someone was to write a spec around SDLdoc then I’m sure
they would have to give SDLdoc a good thorough proof-reading:)
So, I’ll be happy to help anyone out who would like to take up the
project.On Wed, Feb 21, 2001 at 10:18:01PM -0800, Sam Lantinga wrote:

Well, if there is anything more than the man page and the code comments…

There isn’t a formal spec. SDL sort of evolved. If someone has enough time,
I’ll be happy to help them whip up one based on the SDL documentation project.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software


Martin

Bother, said Pooh, and turned the launch key.