Blitz3D+ Command Reference

PeekEvent ( )

Parameters

None.

Description

Fetches the next event without waiting; returns its id, or 0 if the queue is empty.

Requires Extended language mode.

PeekEvent is the non-blocking partner of WaitEvent. It first lets pending native messages through, then takes the next event off the shared queue, makes it the current event for EventID, EventData, EventX, EventY, EventZ and EventSource, and returns its id. When nothing is waiting it returns 0 immediately instead of sleeping.

That makes it the right event call for a program that renders every frame - a canvas game loop or a 3D preview - where WaitEvent would stall the animation. The usual shape drains everything queued, then draws:

While PeekEvent()
    ; ... handle EventID() ...
Wend
; ... update and draw the frame, FlipCanvas ...

Note that, like WaitEvent, it removes the event from the queue - each event is delivered exactly once, whichever of the two commands fetches it.

See it working in the 2D canvas sample.

See also: WaitEvent, EventID, EventData, EventSource, FlushEvents.

Index