sd lpoll even

Started by
2 comments, last by Kylotan 15 years, 10 months ago
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
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).
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?
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.

This topic is closed to new replies.

Advertisement