Events, keyboard & mouseSDL 3.2
SDL_WaitEvent
Sleeps until an event arrives, then takes it out. For tools that only redraw on input.
Signature
bool SDL_WaitEvent(SDL_Event *event);
How it works
A game redraws every frame, so it polls. An editor or a viewer only changes when the user does something; waiting instead of polling drops its CPU use to almost zero while idle. SDL_WaitEventTimeout adds a time limit (e.g. to blink a cursor).
Parameters
eventSDL_Event *
Where to copy the event, or NULL.
Return value
true with an event, false on error.
Example
example.cpp
1SDL_Event e;
2while (running && SDL_WaitEvent(&e)) {
3 handle(e);
4 while (SDL_PollEvent(&e)) handle(e); // drain the rest
5 redraw();
6}