Class Event
An event, pygame.event.Event(type, dict): a type and a dict of attributes (key for a key event,
x and y for a resize), read by Python name through PyAttributes or Dict.
Post one to EventQueue to drive Play without a keyboard, as Gymnasium's
tests do.
[PyName("pygame.event.Event")]
public sealed class Event : IDynamicAttributes, IEquatable<Event>
- Inheritance
-
Event
- Implements
- Inherited Members
- Extension Methods
Remarks
Like pygame's, an event is mutable (attributes can be added or replaced through SetAttr(object, string, object?)
or Dict), equal to another of the same type and an equal dict, and printed as
<Event(768-KeyDown {'key': 97})>. Reading an attribute it lacks raises pygame's
'pygame.event.Event' object has no attribute 'x'. Its hash is its type only, since the dict can change.
Reference: src_c/event.c (pygame-ce 2.5.8).
Constructors
Event(int, object?)
An event of type with the attributes of attributes, pygame's Event(type, dict) or Event(type, **kwargs).
public Event(int type, object? attributes = null)
Parameters
typeintThe event type, an EventType constant or a user type.
attributesobjectThe attributes by Python name: a dictionary, or an anonymous object (
new { key = 97 }), read by From(object?); null for none. The values are shared, not copied.
Exceptions
- ValueError
Thrown when the attributes name
type, with pygame's message:redundant type field in event dict.- TypeError
Thrown when
attributesis no mapping, or has a key that is not a string.
Properties
Dict
The attributes (event.dict), in insertion order; changing it changes the event.
public Info Dict { get; }
Property Value
IsTruthy
public bool IsTruthy { get; }
Property Value
Type
The event type (event.type); fixed at construction.
public int Type { get; }
Property Value
Methods
Equals(Event?)
pygame's ==: the same type and equal dicts (Python's == of the values).
public bool Equals(Event? other)
Parameters
otherEventThe other event.
Returns
Equals(object?)
pygame's == against any object: only an equal Event is equal.
public override bool Equals(object? obj)
Parameters
objobjectThe other object.
Returns
GetHashCode()
The type, the only part that cannot change after construction (pygame's events are unhashable).
public override int GetHashCode()
Returns
- int
The hash.
ToString()
pygame's repr: <Event(768-KeyDown {'key': 97})>.
public override string ToString()
Returns
- string
The text.