[SDL] Keyboard events problem

Ryan C. Gordon icculus at clutteredmind.org
Sun Aug 5 18:45:02 PDT 2001


> {
> 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.







More information about the SDL mailing list