Hi, DaniWeb forum members! I am an above-amateur programmer and this is my first more complex SDL-based program.
I am trying to make the menu of a game, but SDL cannot capture the key presses when a single key was pressed. I use only UP and DOWN arrows, in this code fragment i need to switch between the choices of the menu, but when i hit only one arrow key nothing happens. Instead of that when i hit two arrows (might even be UP and LEFT, any two keys), just then SDL_PollEvent() realizes I have hit a button. I have seen it in the debug and it is strange. I am using Microsoft Visual Studio 2010, SDL library version: 1.2.14. At first it worked almost fine when I used SDL_GetKeyState(), I think this was it`s name. But with it, it switched the options like crazy and I replaced it with SDL_PollEvent(), because it is more sophisticated. The code below is even not my own, but copied from the web, it was the same at different forums. So, is it my code wrong, or it might be the fact that I am using a laptop or because of the SDL version?
In the declaration of the class:
SDL_Event Event;
In a function about events:
while( SDL_PollEvent( &Event ) )
{
switch( Event.type )
{
/* Look for a keypress */
case SDL_KEYDOWN:
/* Check the SDLKey values and move change the coords */
switch( Event.key.keysym.sym )
{
case SDLK_UP:
active--;
break;
case SDLK_DOWN:
active++;
break;
default:
break;
}
}
}
Thanks for those who would help me!