Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Detect key or button press in SDL

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-01-2010
Member
 
Join Date: Jun 2009
Posts: 3,960
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?

Reply With Quote
  #2  
Old 22-01-2010
Member
 
Join Date: May 2008
Posts: 2,283
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.
Reply With Quote
  #3  
Old 22-01-2010
Member
 
Join Date: May 2008
Posts: 2,373
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 22-01-2010
Member
 
Join Date: Jun 2009
Posts: 3,960
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)?
Reply With Quote
  #5  
Old 22-01-2010
Member
 
Join Date: May 2008
Posts: 2,373
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 22-01-2010
Member
 
Join Date: Jun 2009
Posts: 3,960
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Detect key or button press in SDL"
Thread Thread Starter Forum Replies Last Post
Desktop Computer only beeps when i press power button Panchu Hardware Peripherals 6 02-01-2011 05:10 AM
Automating Button Press with Hardware Blesseds Hardware Peripherals 3 31-12-2010 12:13 PM
Zune player freezes when i press any button Author Portable Devices 3 07-10-2009 09:50 PM
Actions depending on the length of the press of a button Elijah Software Development 3 16-03-2009 10:40 AM
Impossible to press a button to install windows xp Jaden Operating Systems 2 28-11-2008 02:30 PM


All times are GMT +5.5. The time now is 11:05 AM.