Strangle problem using keys

Uint8 *keys;
keys=SDL_GetKeyState(NULL);

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }

Is this correct?. I am using SDL-1.2.8 (the stable version when all was
installed). No errors when I compile on my Linux, but the key are not
detected.

I am searching in some games of libsdl.org and in all cases, no errors when
compiling but the keys are not detected?.

Any idea? :?

do you use SDL_PumpEvents() before you GetKeyState.

if not, try it and see if it works…

Not run, again. Compile without errors but the keys are not detected… :?>From: Brian Barrett <brian.ripoff at gmail.com>

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Strangle problem using keys
Date: Tue, 1 Nov 2005 11:18:04 +0000

do you use SDL_PumpEvents() before you GetKeyState.

if not, try it and see if it works…


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

you may also need to use SDL_PollEvents() to clear the event queue, i think.
otherwise ( in windows anyway ) the program becomes unresponsive

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }

Is this correct?. I am using SDL-1.2.8 (the stable version when all was
installed). No errors when I compile on my Linux, but the key are not
detected.

I’d suggest trying

if (keys[SDLK_UP])

instead, since it could be any value except zero.

// MartinOn Tue, 1 Nov 2005, ALTAIR - wrote:

I am using a Linux.>From: Brian Barrett <brian.ripoff at gmail.com>

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Strangle problem using keys
Date: Tue, 1 Nov 2005 16:41:42 +0000

you may also need to use SDL_PollEvents() to clear the event queue, i
think.
otherwise ( in windows anyway ) the program becomes unresponsive

If (keys[SDLK_UP]== 1)

is the same what:

If (keys[SDLK_UP])>From: Martin Storsj?

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Strangle problem using keys
Date: Tue, 1 Nov 2005 19:08:32 +0200 (EET)

On Tue, 1 Nov 2005, ALTAIR - wrote:

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }

Is this correct?. I am using SDL-1.2.8 (the stable version when all was
installed). No errors when I compile on my Linux, but the key are not
detected.

I’d suggest trying

if (keys[SDLK_UP])

instead, since it could be any value except zero.

// Martin


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

It’s not the same if keys[SDLK_UP] is 2 or any other number besides 1 and 0> ----- Original Message -----

From: altairdiv@hotmail.com (ALTAIR -)
To:
Sent: Tuesday, November 01, 2005 11:36 AM
Subject: Re: [SDL] Strangle problem using keys

If (keys[SDLK_UP]== 1)

is the same what:

If (keys[SDLK_UP])

From: Martin Storsj?
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Strangle problem using keys
Date: Tue, 1 Nov 2005 19:08:32 +0200 (EET)

On Tue, 1 Nov 2005, ALTAIR - wrote:

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }

Is this correct?. I am using SDL-1.2.8 (the stable version when all was
installed). No errors when I compile on my Linux, but the key are not
detected.

I’d suggest trying

if (keys[SDLK_UP])

instead, since it could be any value except zero.

// Martin


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

from the wiki
SDL_GetKeyState()
" A value of 1 means that the key is pressed and a value of 0 means that it
is not "

did you try the SDL_PollEvent to clear the event loop?

i imagine if GetKeyState didnt work on linux it would be well documented as
SDL is used…

something like this

void update_input()
{
SDL_Event event;
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
//do something…
}
Uint8 *keys;
keys=SDL_GetKeyState(NULL);

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }
}

i cant see any reason why it wouldn’t work.

please post code if you want more help…

P? Tue, 01 Nov 2005 20:36:27 +0100, skrev ALTAIR - :

If (keys[SDLK_UP]== 1)

is the same what:

If (keys[SDLK_UP])

No. Compile and run this:

— 8< —
#include <stdio.h>

void foo (int a)
{
printf(“foo %i\n”, a);
if (a == 1)
printf(“a == 1!\n”);
if (a)
printf(“a!\n”);
}

int main (int argc, char *argv[])
{
foo(0);
foo(1);
foo(2);
return 0;
}
— 8< —

  • Gerry

No, it’s not the same. The first statement is true if and only if
(keys[SDLK_UP]) is exactly 1. The second statement is true as long as
(keys[SDLK_UP]) evaluates to any non-zero value.

For the cases of 0 and 1 they are equivalent, but if (keys[SDLK_UP])
is 2 or more, or any negative number, or any float value (I don’t
think it’s a float variable but the point is worth making here), then
the statement will still evaluate to true.

If you’re using the actual value of (keys[SDLK_UP]) in a calculation
or control statement somewhere and thus always expect (or require) it
to be 1 or 0, the first is okay. If you only care about true or false,
use the second form.

HTH
-JustinOn 11/1/05, ALTAIR - wrote:

If (keys[SDLK_UP]== 1)

is the same what:

If (keys[SDLK_UP])

if (keys[SDLK_UP])

is the same as:

if (keys[SDLK_UP] != 0)

which is obviously different than:

if (keys[SDLK_UP] == 1)

Only if that variable was of type boolean your statement would be correct,
which it isn’t (Uint8 == unsigned char).

Cheers,
RicardoEm Ter?a 01 Novembro 2005 19:36, o ALTAIR - escreveu:

If (keys[SDLK_UP]== 1)

is the same what:

If (keys[SDLK_UP])

From: Martin Storsj?
Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] Strangle problem using keys
Date: Tue, 1 Nov 2005 19:08:32 +0200 (EET)

On Tue, 1 Nov 2005, ALTAIR - wrote:

if (keys[SDLK_UP]== 1) { move_up(); }
if (keys[SDLK_DOWN]== 1) { move_down(); }

Is this correct?. I am using SDL-1.2.8 (the stable version when all was
installed). No errors when I compile on my Linux, but the key are not
detected.

I’d suggest trying

if (keys[SDLK_UP])

instead, since it could be any value except zero.

// Martin


Bizarreness is the essence of the exotic

If (keys[SDLK_UP])

not run…

#include “SDL.h”
#include “stdio.h”

int main(int argc, char *argv[])
{

unsigned int Tecla;
unsigned char Salir;

  SDL_Event event;

Salir=0;
while (Salir<1)
{

	while (SDL_PollEvent(&event))
	{
		if (event.type==SDLK_UP)
		{
			printf("\nTecla pulsada");
			Salir=1;
		} else {
			printf("\nEsperando...");
		}

		keys=SDL_GetKeyState(NULL);

		if (keys[SDLK_UP])
		{

			printf("\nTecla pulsada");
			Salir=1;
		} else {
			printf("\nEsperando...");
		}

	}
}

return 0;

}

This compile, but not run…

#include “SDL.h”
#include “stdio.h”

int main(int argc, char *argv[])
{

unsigned char Guardian;
unsigned int Tecla;

SDL_Event event;

unsigned char Salir;

Uint8 *keys;


   Salir=0;
while (Salir<1)
{

	SDL_PumpEvents();
	keys=SDL_GetKeyState(NULL);

	if (keys[SDLK_UP])
	{
		printf("\nTecla pulsada");
		Salir=1;
	} else {

		printf("\nEsperando...");
	}

}

return 0;

}

This compile, but not run…

Is possible what the examples of games are using a old techniques?, not
valid for the most modern versions of SDL?

Thanks

I never use the key array trick in SDL. Out of curiosity, did we determine
whether you were pumping events? (SDL_PumpEvents() or some-such)

I don’t recall the rest of the thread, and your post above is… kinda bare :)On Wed, Nov 02, 2005 at 06:00:08AM +0000, ALTAIR - wrote:

If (keys[SDLK_UP])

not run…


-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/

Maybe this will help:

http://gpwiki.org/index.php/SDL:Tutorials:Keyboard_Input_using_an_Event_Loop

ChrisOn 11/2/05, ALTAIR - wrote:

Is possible what the examples of games are using a old techniques?, not
valid for the most modern versions of SDL?


E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

Of course not you haven’t even initialized SDL. How could it work?On Wednesday 02 November 2005 08:30, ALTAIR - wrote:

#include “SDL.h”
#include “stdio.h”

int main(int argc, char *argv[])
{

unsigned int Tecla;
unsigned char Salir;

  SDL_Event event;

Salir=0;
while (Salir<1)
{

  while (SDL_PollEvent(&event))
  {
  	if (event.type==SDLK_UP)
  	{
  		printf("\nTecla pulsada");
  		Salir=1;
  	} else {
  		printf("\nEsperando...");
  	}

  	keys=SDL_GetKeyState(NULL);

  	if (keys[SDLK_UP])
  	{

  		printf("\nTecla pulsada");
  		Salir=1;
  	} else {
  		printf("\nEsperando...");
  	}

  }

}

return 0;
}

This compile, but not run…