SDL_PeepEvents(3)

✨ SDL_PeepEvents ✨

ok so bestie, we're in the SDL3 FUNCTIONS section of the SDL_PeepEvents(3) manual and this one is genuinely such a vibe β€” it's the peeky-looky function for your event queue πŸ’…

πŸŽ€ NAME πŸŽ€

SDL_PeepEvents β€” check the event queue for messages and optionally return them.

like, it goes in, it looks around, and it maybe brings stuff back. iconic behavior tbh.


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_events.h>

int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_EventAction action, Uint32 minType, Uint32 maxType);

πŸ¦‹ DESCRIPTION πŸ¦‹

action can be literally any of these three, and ngl they each have a whole different personality:

  • SDL_ADDEVENT β€” up to numevents events will be added to the back of the event queue. yes, back. the end. the tail. the line-ends-here spot 🫢
  • SDL_PEEKEVENT β€” numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will _not_ be removed from the queue. look-but-don't-touch energy fr fr. πŸ‘€ and listen β€” if you pass NULL for events, then numevents is ignored and the total number of matching events will be returned. free little count for you, no notes.
  • SDL_GETEVENT β€” up to numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will be removed from the queue. okay so this one actually takes them. gone. bye. snatched. πŸ’€
heads up bestie!! you may have to call SDL_PumpEvents() before calling this function. otherwise, the events may not be ready to be filtered when you call SDL_PeepEvents(). don't skip the pump, that's the whole ritual ✨

πŸ’– FUNCTION PARAMETERS πŸ’–

  • events β€” destination buffer for the retrieved events, may be NULL to leave the events in the queue and return the number of events that would have been stored. lowkey a "just tell me how many" mode and honestly? we love a buffer-less option.
  • numevents β€” if action is SDL_ADDEVENT, the number of events to add back to the event queue; if action is SDL_PEEKEVENT or SDL_GETEVENT, the maximum number of events to retrieve. same name, different job, main character duality tbh πŸ‘‘
  • action β€” action to take; see [Remarks](#remarks) for details.
  • minType β€” minimum value of the event type to be considered; SDL_EVENT_FIRST is a safe choice. the safe choice!! the little safety blanket 🧚
  • maxType β€” maximum value of the event type to be considered; SDL_EVENT_LAST is a safe choice. matching safety blanket, we love a symmetrical queen 🌈

⭐ RETURN VALUE ⭐

Returns the number of events actually stored, or -1 on failure; call SDL_GetError() for more information. so if you see that -1... go ask SDL_GetError() what happened, she always knows 😭


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this function from any thread. no cap. every thread. go off 🫢


πŸ’œ AVAILABILITY πŸ’œ

This function is available since SDL 3.2.0.


πŸ“ SEE ALSO πŸ“


and that's the whole page bestie!! brought to you by Simple Directmedia Layer, running SDL 3.4.18 β€” mwah, go peek some events, ily πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from