Wiki Page Content

Differences between revisions 16 and 17
Revision 16 as of 2016-11-20 21:55:42
Size: 1483
Comment: Changed line comments to block comments in example.
Revision 17 as of 2018-10-30 06:19:43
Size: 1594
Editor: LionKimbro
Comment: Clarified that the 1/0 returned, when event is passed, refers to the event that was immediately stored.
Deletions are marked like this. Additions are marked like this.
Line 32: Line 32:
If '''event''' is not NULL, the next event is removed from the queue and stored in the [[SDL_Event]] structure pointed to by '''event'''. If '''event''' is not NULL, the next event is removed from the queue and stored in the [[SDL_Event]] structure pointed to by '''event'''.  The 1 returned refers to this event, immediately stored in the SDL Event structure -- not an event to follow.

SDL_PollEvent

Use this function to poll for currently pending events.

Syntax

int SDL_PollEvent(SDL_Event* event)

Function Parameters

event

the SDL_Event structure to be filled with the next event from the queue, or NULL

Return Value

Returns 1 if there is a pending event or 0 if there are none available.

Code Examples

while (1) {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        /* handle your event here */
    }
    /* do some other stuff here -- draw your app, etc. */
}

Remarks

If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event. The 1 returned refers to this event, immediately stored in the SDL Event structure -- not an event to follow.

If event is NULL, it simply returns 1 if there is an event in the queue, but will not remove it.

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

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