Hello all,
I’m new to SDL and I’m probably looking over something terribly simple, but I would appreciate it if someone could point out what I’m doing wrong…
Here’s a simple program that I’ve compiled and ran, but I can’t get it to read any keys. I’ve tried rearranging the code various ways, but I can’t get it to notice a SDL_KEYDOWN event. It always passes over it. SDL_QUIT seems to work right though…
Hope somebody can help me, and I apologize for bugging you all.
MadCat13
int KeyPressed( SDL_keysym * whichKey )
{
if (whichKey->sym == SDLK_a)
{
printf(“You pressed the ‘A’ key.\n”);
return 0;
}
if (whichKey->sym == SDLK_b)
{
printf(“You pressed the ‘B’ key.\n”);
return 0;
}
if (whichKey->sym == SDLK_c)
{
printf(“You pressed the ‘C’ key.\n”);
return 0;
}
if (whichKey->sym == SDLK_ESCAPE)
{
printf(“Quitting…\n”);
return -1;
}
printf(“You pressed some other key.\n”);
return 0;
}
int PollKeyboard( void )
{
SDL_Event event;
int Quit = 0;
while( SDL_PollEvent ( &event ))
{
switch(event.type)
{
case SDL_KEYDOWN:
Quit = KeyPressed(&event.key.keysym);
break;
case SDL_QUIT:
Quit = -1;
break;
}
}
return Quit;
}
int main(int argv, char ** argc)
{
int Quit = 0;
printf(“Polling keyboard…\n\n”);
while( Quit == 0 )
{
Quit = PollKeyboard();
}
return 0;
}