Class PygameEventQueue
A PygameContext's event queue (pygame.event): filled by the context's display window (keys,
its close button, resizes) and by Post(Event), drained by Get(). Play
drains its context's queue once per frame, so posting events is how a program or a test plays an env without a
keyboard, as Gymnasium's own tests do with pygame.event.post.
public sealed class PygameEventQueue
- Inheritance
-
PygameEventQueue
- Inherited Members
- Extension Methods
Remarks
One per context; the static EventQueue is Default's, process-wide as SDL's
is, so a callback deep inside play can post to it without a handle. The footgun is pygame's: two loops
draining one queue steal each other's events, so two games at once need two contexts, and tests that share the
default queue must not run in parallel with each other.
Thread-safe: any thread may post (a viewer's UI thread does), and the window's input moves into the queue only when
Get() or Pump() runs (SDL's SDL_PumpEvents), on the caller's thread, so the display
surface changes size only there. The display's Quit() empties it, as pygame.quit()
drops pending events. Unlike pygame, posting works before any display is set (there is no video subsystem to
initialize), and the queue has no capacity limit and no blocked types.
Reference: src_c/event.c (pygame-ce 2.5.8).
Properties
Context
The context this queue belongs to, whose Display feeds it.
public PygameContext Context { get; }
Property Value
Count
The number of pending events, without pumping; for tests and diagnostics.
public int Count { get; }
Property Value
Methods
Clear()
pygame.event.clear(): drops every pending event, the window's buffered input included.
public void Clear()
Get()
pygame.event.get(): pumps the context's window input (Pump()), then takes every pending event,
oldest first.
public IReadOnlyList<Event> Get()
Returns
- IReadOnlyList<Event>
The events, empty when there are none; the caller owns the list.
Post(Event)
pygame.event.post(event): appends an event; the next Get() returns it after the ones already
pending.
public void Post(Event @event)
Parameters
eventEventThe event; queued as is (not copied), so changing it before it is taken changes what is read.
Exceptions
- ArgumentNullException
Thrown when
eventis null.
Pump()
pygame.event.pump(): moves the context's window input into the queue as pygame's events, resizing the
display surface for a resize, without taking anything out. A no-op without an interactive window.
public void Pump()