Wiki Page Content

Differences between revisions 11 and 12
Revision 11 as of 2010-10-11 05:31:37
Size: 2281
Editor: SheenaSmith
Comment: update content - pointers, structs
Revision 12 as of 2013-07-22 13:53:59
Size: 2290
Editor: axper
Comment: added #!highlight cpp for second code example
Deletions are marked like this. Additions are marked like this.
Line 33: Line 33:
*
{{{
{{{#!highlight cpp
Line 55: Line 54:
*

DRAFT

SDL_PollEvent

Use this function to poll for currently pending events.

Syntax

int SDL_PollEvent(SDL_Event* event)

Function Parameters

event

if not NULL, the next event is removed from the queue and stored in that area -or- the [[SDL_Event]] structure to be filled with the next event from the queue, or NULL

Return Value

Returns 1 if there are any pending events or 0 if there are none available; call SDL_GetError() for more information.

green

Code Examples

while(1){
    SDL_Event event;
    if(SDL_PollEvent(&event)){
         // handle your event here
    }
    // do some other stuff here -- draw your app, play your music, perform other operations...
}

SDL_Event event; /* Event structure */

.
.
.
/* Check for events */
while(SDL_PollEvent(&event)) {  /* Loop until there are no events left on the queue */
  switch(event.type) { /* Process the appropriate event type */
    case SDL_KEYDOWN:  /* Handle a KEYDOWN event */
      printf("Oh! Key press\n");
      break;
    case SDL_MOUSEMOTION:
      .
      .
      .
    default: /* Report an unhandled event */
      printf("I don't know what this event is!\n");
  }
}

Remarks

*If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure union pointed to by event.

As this function implicitly calls SDL_PumpEvents(), you can only call this function in the thread that set the video mode. * green

SDL_PollEvent() is the favored way of receiving system events since it can be done from the main loop and does not suspend the main loop while waiting on an event to be posted.


CategoryAPI, CategoryEvents

None: SDL_PollEvent (last edited 2018-10-30 06:19:43 by LionKimbro)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit