logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

SDL_PollEvent - Poll for currently pending events.

Availability

       This function is available since SDL 3.2.0.

Description

       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 from the
       queue.

       As this function may implicitly call 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.

       The common practice is to fully process the event queue once every frame, usually as a first step  before
       updating the game's state:

              while (game_is_still_running) {
                  SDL_Event event;
                  while (SDL_PollEvent(&event)) {  // poll until all events are handled!
                      // decide what to do with this event.
                  }

                  // update game state, draw the current frame
              }

Function Parameters

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

Header File

       Defined in SDL3/SDL_events.h

Name

       SDL_PollEvent - Poll for currently pending events.

Return Value

       Returns true if this got an event or false if there are none available.

See Also

(3), SDL_PushEvent(3), (3), SDL_WaitEvent(3), (3), SDL_WaitEventTimeout(3)

Simple Directmedia Layer                           SDL 3.2.10                                   SDL_PollEvent(3)

Synopsis

#include"SDL3/SDL.h"boolSDL_PollEvent(SDL_Event*event);

Thread Safety

       This function should only be called on the main thread.

See Also