Keyboard events problem

Hi, I’m new to this list…

I have been learning the SDL library functions and on
two different computers and in linux and BeOS, I have
a little problem getting the keyboard events.

Take the following prog:

#include<stdio.h>
#include"SDL/SDL.h"
main()
{
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);

while(1)
{
if (SDL_PollEvent($event) != NULL)
printf("\n%d",&event.key.keysym);
/* Or similar without the & */
}
SDL_Quit();
}-----------

This produces a constant value continuously at keysym
in the console and X11 mode. All graphics functions
work fine. Is there some additional Initialization for
the keyboard events?? The documentation doesnt suggest
as such.

Would someone please show me a little demo prog that
just outputs in printf variable keys pressed. I havent
found such a prog yet… the testkeys.c in SDL-1.2.2
just shows the values of the keys… doesnt input
anything. I’m using two very standard computers and
even the -Wall arg to gcc doesnt give any warnings.
Thanks for help in advance.
Ghazan Haider


Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

{
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);

(I’m not sure if this is meant to be pseudocode, so I’m listing some
things that might not be problems…)

You need to call SDL_SetVideoMode(), or you won’t get events.

while(1)
{
if (SDL_PollEvent($event) != NULL)

SDL_PollEvent() returns an integer, so it should be “!= 0”…

      printf("\n%d",&event.key.keysym);

You need to check for event.type and make sure it’s either SDL_KEYDOWN or
SDL_KEYUP; otherwise, event.key.keysym is bogus.

Secondly, &event.key.keysym is the address of the symbol. You don’t want
the ‘&’ char, otherwise it WILL always be a constant value.

–ryan.

You need to call SDL_SetVideoMode(), or you won’t
get events.

That solved the thing entirely. Thanks.
.__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/