Jump to content
  • Advertisement
Sign in to follow this  
knobby67

sd lpoll even

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I'm porting some code over from GLX to SDL but am having some problems with key detection so I tried this simple bit of code and it still didn't work? Do I need to set up screens or something?
int main()
{
	int x=0;
	extern void DetectButtons(void);
	SDL_Init( SDL_INIT_EVERYTHING );
/****************** init the system ************************************/
do
{
DetectButtons();
sleep(1);
x++;
}while(x<10);
}
the event loop is
void DetectButtons(void)
{

       SDL_PollEvent( &DetectEvent );

        
        printf("event %d    ",DetectEvent.type);
        
         	switch(DetectEvent.type)
         	{
         		case SDL_KEYDOWN:         
      			printf("Key press\n");
      			break;
    			case SDL_MOUSEMOTION:
        		printf("mouse motion\n");
        		break;
        
        
        	}
        


}
Detect event is a global. Thanks:) Sorry totally forgot how to post code thought it was
 
? Obviously not

Share this post


Link to post
Share on other sites
Advertisement
There's no loop in your event loop, thus making it not an event loop. Search this forum for examples of how to do the event loop properly (ie. call SDL_PollEvent in a while loop that checks the return value).

Share this post


Link to post
Share on other sites
the whole detectbutton function is in a loop called from main. If I add
while (SDL_PollEvent(&DetectEvent))
{

all the while does there is says keep reading if there's a number of events coming together?

Share this post


Link to post
Share on other sites
I don't know what you're trying to say. But you should empty the event queue each time, not just handle one event per iteration of your main loop.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!