Detect key or button press in SDL
I have a code:
Code:
SDL_Event event;
while(continue){
/*full instructions*/
quitOrEsc(&continue, event);
}
With the function quitOrEsc:
Code:
/*Procedure: verified if the ESC key is pressed or if it was an event SDL_QUIT (v)
without blocking the execution of the program
Data: Address varible loop and variable of the event.
EB: zero of the variable if either event is detected.
Preconditions: have initialized SDL
*/
void quitOrEsc(int *continue, SDL_Event event)
{
SDL_PollEvent(&event);
switch(event.type){
case SDL_QUIT:
*continue = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym){
case SDLK_ESCAPE:
*continue = 0;
break;
default:
break;
}
break;
default:
break;
}
}
Unfortunately I'm pressing the escape key or clicking on the cross but still it won't leave it, do you know why? How will the program come to know whether I have clicked any key or button?
Re: Detect key or button press in SDL
I do not see what you used for the event to pass by value to your function quitOrEsc, otherwise it looks to me like ok. You can put breakpoints to see if you get in the functions that interest and draw.
Do you code this for your office? Because the code that you do not show us might contain a continuous code which may be important for us to solve your problem.
Re: Detect key or button press in SDL
If that's your problem lies in the "supportSurV ()" where do you already SQL_PollEvent, so that the following function "quitOrEsc()" will have nothing to put under tooth .
And I see that a loop with a wait time of 5 ms (200 fps anyway). On Windows, if you want a short time, must go nag at helping "while (getticks () - old <5). The timer under Windows on an accuracy of 10 to 15ms, or just good for the 50 to 60 fps.
I just see more detail on your event management and its not too much. In general we do a single call SQL_PollEvent or SQL_WaitEvent and one switch on "event.type". After you can call other functions in the branches of the switch.
Re: Detect key or button press in SDL
Yes it is the same program.
For the expectation that I change the value depending on the number of calculations that the program must perform. It serves me just to run slowly so as not to go too fast, so I do not care for accuracy.
To appeal to SDL_WaitEvent I do when? Before the while? After I'm just a switch on the event.type while (so in my position)?
Re: Detect key or button press in SDL
It's not complicated, however, provided that there is only one call to SDL_PollEvent () throughout your program.
So call this function once and transmert structure "event" at your office supportSurV () or quitOrEsc (), style (main.c):
Code:
if (SDL_PollEvent(&event))
{
supportSurV(&vector, event);
quitOrEsc(&continue, event);
}
And of course, remove the appeal to SDL_PollEvent () in the two sub-functions.
Re: Detect key or button press in SDL
Thank you very much
Another question, how to use the debugger Code:: Blocks?
In Project-> Build option I have ticked "Produce debugging symbols" and I put a stop point in the program, but when I compile in debug launch in software that launches normally, it does not stop the breakpoint ....
Because I have a bug and I really do not understand where it comes. If I really find it I'll post the sources updated maybe you can still save me.