No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera------------------
Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”

hey Bruce,

another way to see what keys are pressed is to watch the key down and key up
events.

this could help you figure out if a key was pressed since you last checked
or not.> ----- Original Message -----

From: bruce@opengl.com.br (Bruce Barrera)
To:
Sent: Wednesday, January 28, 2004 1:19 PM
Subject: [SDL] No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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

If NO keys are pressed? Or just no keys you care about?

If the former, I suppose you could do a quick ‘for’ loop to check if
any keys[X] are set. If so, then we know SOME key is down.

If the latter, just set a boolean before you check for keys you care about.
e.g.:

keys = SDL_GetKeyState(NULL);
any_key_pressed = FALSE;

if (key[SDLK_UP])
{
do something;
any_key_pressed = TRUE;
}
else if (key[SDLK_DOWN])
{
do something else;
any_key_pressed = TRUE;
}

etc.

-bill!On Wed, Jan 28, 2004 at 07:19:52PM -0200, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m not sure, but try if SDL_GetKeyState returns NULL if no key was
pressed.On Wed, Jan 28, 2004 at 07:19:52PM -0200, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???


saf at http://TrashMail.net/
No more spam, free disposable email addresses.

nope thats not correct, it always returns a pointer to the state array of
the keys, even if no keys are pressed.> ----- Original Message -----

From: sdl@xy1.org (Stephan Ferraro)
To:
Sent: Wednesday, January 28, 2004 1:41 PM
Subject: Re: [SDL] No key pressed

On Wed, Jan 28, 2004 at 07:19:52PM -0200, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m not sure, but try if SDL_GetKeyState returns NULL if no key was
pressed.


saf at http://TrashMail.net/
No more spam, free disposable email addresses.


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

No Alan, i need to test anyway.
Thats why I have an update function in my game that is called if no events
occurred in that frame, and then it checks a variable, “keys”, to see if in
last frame occurred a key press. I cannot update my game in the KEY_DOWN or
KEY_UP event. So I made this way. So if no key was pressed, how to know ?

In my last frame an KEY_UP event occurred and SDL_GetKeyState was called…
I need to know how what value it returns me if no key was pressed.
I will test NULL and I do not want to do a array scan like Bill said testing
each key to see if its value is 0 or 1…

[]s
Bruce> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alan Wolfe
Sent: quarta-feira, 28 de janeiro de 2004 19:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

hey Bruce,

another way to see what keys are pressed is to watch the key down and key up
events.

this could help you figure out if a key was pressed since you last checked
or not.

----- Original Message -----
From: @Bruce_Barrera (Bruce Barrera)
To:
Sent: Wednesday, January 28, 2004 1:19 PM
Subject: [SDL] No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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


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

Can’t you just keep a running tally of KEY_DOWN and KEY_UP’s?

Sint32 myTally = 0;

if ( there was a KEY_DOWN event ) myTally++;
if ( there was a KEY_UP event ) myTally–;

if ( myTally == 0 ) then no keys are pressed.

  • Jeremiah
    http://inlovewithGod.com-----Original Message-----
    From: sdl-admin at libsdl.org on behalf of Bruce @ OpenGL
    Sent: Wed 1/28/2004 5:24 PM
    To: sdl at libsdl.org
    Cc:
    Subject: RE: [SDL] No key pressed

    No Alan, i need to test anyway.
    Thats why I have an update function in my game that is called if no events
    occurred in that frame, and then it checks a variable, “keys”, to see if in
    last frame occurred a key press. I cannot update my game in the KEY_DOWN or
    KEY_UP event. So I made this way. So if no key was pressed, how to know ?

    In my last frame an KEY_UP event occurred and SDL_GetKeyState was called…
    I need to know how what value it returns me if no key was pressed.
    I will test NULL and I do not want to do a array scan like Bill said testing
    each key to see if its value is 0 or 1…

    []s
    Bruce

    -----Original Message-----
    From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
    Alan Wolfe
    Sent: quarta-feira, 28 de janeiro de 2004 19:30
    To: sdl at libsdl.org
    Subject: Re: [SDL] No key pressed

    hey Bruce,

    another way to see what keys are pressed is to watch the key down and key up
    events.

    this could help you figure out if a key was pressed since you last checked
    or not.

    ----- Original Message -----
    From: “Bruce @ OpenGL”
    To:
    Sent: Wednesday, January 28, 2004 1:19 PM
    Subject: [SDL] No key pressed

    Hi folks,

    To see which key was pressed, I use SDL_GetKeyState in this way:

    Uint8* keys;
    keys = SDL_GetKeyState(NULL);

    then I check here:

    if (keys[SDLK_UP])
    { do something; }

    But and if I want to check if no key was pressed, after a call to
    SDL_GetKeyState ???

    Thnxs,

    Bruce Christopher Barrera

    Moderador da lista de discuss?o OpenGL_Brasil
    http://br.groups.yahoo.com/group/opengl_brasil/
    Moderador da se??o OpenGL do F?rum do PDJ Brasil
    http://www.pdj.com.br/forum

    “Existem 10 tipos de pessoas. As que entendem binario e as que nao
    entendem…”


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


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


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

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/ms-tnef
Size: 6174 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040128/2104805f/attachment.bin

Bruce, SDL doesnt keep track of anything like that.

heres what you do.

1)make a global variable called something like “KeyPressedLastFrame”

  1. set this to 0 when starting up.

  2. on your keydown/keyup events (whichever is appropriate), set this
    variable to 1.

  3. in your loop where you call SDL_GetKeyState, if this variable is 1, you
    know a key was pressed since you last checked, if this variable is 0, you
    know a key was not pressed since you last checked.

  4. after you check to see if it was pressed or not and do the appropriate
    processing, set this variable back to 0.

This is what i meant by using the keyup/keydown events to help you figure
out if a key was pressed since the last time you checked or not.> ----- Original Message -----

From: bruce@opengl.com.br (Bruce Barrera)
To:
Sent: Wednesday, January 28, 2004 2:24 PM
Subject: RE: [SDL] No key pressed

No Alan, i need to test anyway.
Thats why I have an update function in my game that is called if no events
occurred in that frame, and then it checks a variable, “keys”, to see if
in
last frame occurred a key press. I cannot update my game in the KEY_DOWN
or
KEY_UP event. So I made this way. So if no key was pressed, how to know ?

In my last frame an KEY_UP event occurred and SDL_GetKeyState was
called…
I need to know how what value it returns me if no key was pressed.
I will test NULL and I do not want to do a array scan like Bill said
testing
each key to see if its value is 0 or 1…

[]s
Bruce

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alan Wolfe
Sent: quarta-feira, 28 de janeiro de 2004 19:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

hey Bruce,

another way to see what keys are pressed is to watch the key down and key
up
events.

this could help you figure out if a key was pressed since you last checked
or not.

----- Original Message -----
From: “Bruce @ OpenGL”
To:
Sent: Wednesday, January 28, 2004 1:19 PM
Subject: [SDL] No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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


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


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

I may be misunderstanding you, but it seems that you only want to update
your game when no keys are currently pressed. Yes?

Maybe the best thing to do is before you start your game loop,
initialize an int to zero, and scan all the keys incrememting your int
for each key currently pressed.

Then watch for key events, and decrement your counter when you see
KEY_UP, and increment it when you see KEY_DOWN. That way, when your
counter is 0, you know nothing is pressed. Non-zero means there is.On Wed, 2004-01-28 at 17:24, Bruce @ OpenGL wrote:

No Alan, i need to test anyway.
Thats why I have an update function in my game that is called if no events
occurred in that frame, and then it checks a variable, “keys”, to see if in
last frame occurred a key press. I cannot update my game in the KEY_DOWN or
KEY_UP event. So I made this way. So if no key was pressed, how to know ?

In my last frame an KEY_UP event occurred and SDL_GetKeyState was called…
I need to know how what value it returns me if no key was pressed.
I will test NULL and I do not want to do a array scan like Bill said testing
each key to see if its value is 0 or 1…

[]s
Bruce

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alan Wolfe
Sent: quarta-feira, 28 de janeiro de 2004 19:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

hey Bruce,

another way to see what keys are pressed is to watch the key down and key up
events.

this could help you figure out if a key was pressed since you last checked
or not.

----- Original Message -----
From: “Bruce @ OpenGL”
To:
Sent: Wednesday, January 28, 2004 1:19 PM
Subject: [SDL] No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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


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


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

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m curious what sort of system would need to know explicitly when no
keys are pressed? Surely most systems only perform explicit actions when
keys are pressed, not when they’re not?On Wed, 2004-01-28 at 21:19, Bruce @ OpenGL wrote:

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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

http://www.mattsscripts.co.uk/

  • A great source for free CGI and stuff

Logic doesn’t apply to the real world.
– Marvin Minsky

Can’t you just keep a running tally of KEY_DOWN and KEY_UP’s?

Sint32 myTally = 0;

if ( there was a KEY_DOWN event ) myTally++;
if ( there was a KEY_UP event ) myTally–;

if ( myTally == 0 ) then no keys are pressed.

Because technically there is a key down, the ‘key down’ and 'key up’
keys :)On Wed, 2004-01-28 at 22:36, Martell, Jeremiah wrote:

-----Original Message-----
From: sdl-admin at libsdl.org on behalf of Bruce @ OpenGL
Sent: Wed 1/28/2004 5:24 PM
To: sdl at libsdl.org
Cc:
Subject: RE: [SDL] No key pressed

No Alan, i need to test anyway.
Thats why I have an update function in my game that is called if no events
occurred in that frame, and then it checks a variable, “keys”, to see if in
last frame occurred a key press. I cannot update my game in the KEY_DOWN or
KEY_UP event. So I made this way. So if no key was pressed, how to know ?

In my last frame an KEY_UP event occurred and SDL_GetKeyState was called…
I need to know how what value it returns me if no key was pressed.
I will test NULL and I do not want to do a array scan like Bill said testing
each key to see if its value is 0 or 1…

[]s
Bruce

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alan Wolfe
Sent: quarta-feira, 28 de janeiro de 2004 19:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

hey Bruce,

another way to see what keys are pressed is to watch the key down and key up
events.

this could help you figure out if a key was pressed since you last checked
or not.

----- Original Message -----
From: “Bruce @ OpenGL”
To:
Sent: Wednesday, January 28, 2004 1:19 PM
Subject: [SDL] No key pressed

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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


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


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


http://www.mattsscripts.co.uk/

  • A great source for free CGI and stuff

It is convenient that there be gods, and, as it is convenient, let us
believe there are.
– Publius Ovidius Naso (Ovid)

My app is a girl running in a tunnel…when no keys are pressed, the velocity of the girl must be slowing down.
If the user is not pressing the SDLK_UP, then no velocity is being charged to the girl and then she must stop!
Thats why I need to know if no keys are being pressed.

The way i solved my problem was not checking for keys but each frame, if a SDLK_UP is being pressed, I increase
her velocity by 0.005 and always decrease by 0.002

Then if user is not pressing SDLK_UP, the velocity will be descrease by 0.002 until her stop. This way I assure that
she will stop if no keys are being pressed.

Well, I saw that the only way to know if no key was pressed is scanning the array of keys. Well, this is not the way I
would like to do, but I think that scanning a 256 positions array will not be so costly, will it?

I dont want to make global variables since my app is all Object Oriented and such.

Thnxs for everyones reply,

Cheers,
Bruce> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Matt Wilson
Sent: quarta-feira, 28 de janeiro de 2004 23:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

On Wed, 2004-01-28 at 21:19, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m curious what sort of system would need to know explicitly when no
keys are pressed? Surely most systems only perform explicit actions when
keys are pressed, not when they’re not?

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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

http://www.mattsscripts.co.uk/

  • A great source for free CGI and stuff

Logic doesn’t apply to the real world.
– Marvin Minsky


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

instead of making it a global variable, you could make it a variable within
main.

not sure how global variables go against OOP design but whatever.

you could also have done it this way (this is pseudo code)

if up key is pressed
increase velocity
else
decrease velocity

instead of like this

if up key is pressed
increase velocity

decrease velocity

glad you got it to work though> ----- Original Message -----

From: bruce@opengl.com.br (Bruce Barrera)
To:
Sent: Thursday, January 29, 2004 5:17 AM
Subject: RE: [SDL] No key pressed

My app is a girl running in a tunnel…when no keys are pressed, the
velocity of the girl must be slowing down.
If the user is not pressing the SDLK_UP, then no velocity is being charged
to the girl and then she must stop!
Thats why I need to know if no keys are being pressed.

The way i solved my problem was not checking for keys but each frame, if a
SDLK_UP is being pressed, I increase
her velocity by 0.005 and always decrease by 0.002

Then if user is not pressing SDLK_UP, the velocity will be descrease by
0.002 until her stop. This way I assure that
she will stop if no keys are being pressed.

Well, I saw that the only way to know if no key was pressed is scanning the
array of keys. Well, this is not the way I
would like to do, but I think that scanning a 256 positions array will not
be so costly, will it?

I dont want to make global variables since my app is all Object Oriented and
such.

Thnxs for everyones reply,

Cheers,
Bruce

-----Original Message-----
From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Matt Wilson
Sent: quarta-feira, 28 de janeiro de 2004 23:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

On Wed, 2004-01-28 at 21:19, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m curious what sort of system would need to know explicitly when no
keys are pressed? Surely most systems only perform explicit actions when
keys are pressed, not when they’re not?

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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

http://www.mattsscripts.co.uk/

  • A great source for free CGI and stuff

Logic doesn’t apply to the real world.
– Marvin Minsky


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


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

i have more ifs than just one =)
i need to test key left, key down, key right and can do a ‘else if’ because the user can press up AND left at same time.

but i got it workin, no problem!

thanxs a lot alan!

[]s
Bruce> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alan Wolfe
Sent: quinta-feira, 29 de janeiro de 2004 15:24
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

instead of making it a global variable, you could make it a variable within
main.

not sure how global variables go against OOP design but whatever.

you could also have done it this way (this is pseudo code)

if up key is pressed
increase velocity
else
decrease velocity

instead of like this

if up key is pressed
increase velocity

decrease velocity

glad you got it to work though

----- Original Message -----
From: @Bruce_Barrera (Bruce Barrera)
To:
Sent: Thursday, January 29, 2004 5:17 AM
Subject: RE: [SDL] No key pressed

My app is a girl running in a tunnel…when no keys are pressed, the
velocity of the girl must be slowing down.
If the user is not pressing the SDLK_UP, then no velocity is being charged
to the girl and then she must stop!
Thats why I need to know if no keys are being pressed.

The way i solved my problem was not checking for keys but each frame, if a
SDLK_UP is being pressed, I increase
her velocity by 0.005 and always decrease by 0.002

Then if user is not pressing SDLK_UP, the velocity will be descrease by
0.002 until her stop. This way I assure that
she will stop if no keys are being pressed.

Well, I saw that the only way to know if no key was pressed is scanning the
array of keys. Well, this is not the way I
would like to do, but I think that scanning a 256 positions array will not
be so costly, will it?

I dont want to make global variables since my app is all Object Oriented and
such.

Thnxs for everyones reply,

Cheers,
Bruce

-----Original Message-----
From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Matt Wilson
Sent: quarta-feira, 28 de janeiro de 2004 23:30
To: sdl at libsdl.org
Subject: Re: [SDL] No key pressed

On Wed, 2004-01-28 at 21:19, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

But and if I want to check if no key was pressed, after a call to
SDL_GetKeyState ???

I’m curious what sort of system would need to know explicitly when no
keys are pressed? Surely most systems only perform explicit actions when
keys are pressed, not when they’re not?

Thnxs,

Bruce Christopher Barrera

Moderador da lista de discuss?o OpenGL_Brasil
http://br.groups.yahoo.com/group/opengl_brasil/
Moderador da se??o OpenGL do F?rum do PDJ Brasil
http://www.pdj.com.br/forum

“Existem 10 tipos de pessoas. As que entendem binario e as que nao
entendem…”


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

http://www.mattsscripts.co.uk/

  • A great source for free CGI and stuff

Logic doesn’t apply to the real world.
– Marvin Minsky


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


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


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

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

As I understand it, SDL_GetKeyState() probably doesn’t work in the way
that you think it does. You only ever need to call it once, at the
beginning of your program, and from there on in it will always contain the
current state of the keyboard (as long as you keep pumping/polling events).

Others have explained how you misunderstand the alternative of dealing
with key events.

Also, as for not liking global variables - if you’re using C++ and not
C, do you know about static variables? You declare them inside the scope
of a function, but they save their value between each time the function is
called.

JamesOn Wed, 28 Jan 2004 19:19:52 -0200, Bruce @ OpenGL wrote:

Thanks James, I will consider the use of static variables. I could have
used them, thnxs again.

[]s
Bruce

James Gregory wrote:>On Wed, 28 Jan 2004 19:19:52 -0200, Bruce @ OpenGL wrote:

Hi folks,

To see which key was pressed, I use SDL_GetKeyState in this way:

Uint8* keys;
keys = SDL_GetKeyState(NULL);

then I check here:

if (keys[SDLK_UP])
{ do something; }

As I understand it, SDL_GetKeyState() probably doesn’t work in the way
that you think it does. You only ever need to call it once, at the
beginning of your program, and from there on in it will always contain the
current state of the keyboard (as long as you keep pumping/polling events).

Others have explained how you misunderstand the alternative of dealing
with key events.

Also, as for not liking global variables - if you’re using C++ and not
C, do you know about static variables? You declare them inside the scope
of a function, but they save their value between each time the function is
called.

James


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