pygame Events
This page lists the events that renpy.pygame produces, the attributes each one carries, and how they differ from the events of pygame-ce.
Events reach a game through the event method of a
creator-defined displayable. Ren'Py blocks the event types it
does not use, so they are never delivered; the Default column below says
which types reach displayables without any configuration. To receive another
type, add it to config.pygame_events.
Every event is an instance of pygame.Event (also available as
pygame.event.Event), and can be compared with the constants in the
Event column, such as ev.type == pygame.KEYDOWN. An event's attributes
are also available as the dictionary ev.dict, and
pygame.event.event_name(ev.type) gives the first name in the Event
column.
Every event has a timestamp attribute: the time SDL queued the event,
as a float number of seconds since SDL started, or 0.0 for an event the game
created itself. It is not part of ev.dict.
The window attribute is the main window, as returned by
pygame.display.get_window(), when SDL associates the event with it, and
None otherwise.
The Event column gives the Ren'Py name of each type first, then other names
for the same type, such as the pygame-ce names, and finally the name SDL
uses. Positions and sizes are in the units SDL reports them in, and Ren'Py
gives the event's position in virtual pixels separately, as the x and
y arguments to the event method.
The event types that are available, and the attributes each event has, come from the version of SDL that Ren'Py uses, and may change in major versions of Ren'Py.
Application Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
QUIT(
SDL_EVENT_QUIT) |
Yes |
None |
None |
TERMINATINGAPP_TERMINATING(
SDL_EVENT_TERMINATING) |
Yes |
None |
None |
LOWMEMORYAPP_LOWMEMORY(
SDL_EVENT_LOW_MEMORY) |
Yes |
None |
None |
WILLENTERBACKGROUNDAPP_WILLENTERBACKGROUND(
SDL_EVENT_WILL_ENTER_BACKGROUND) |
Yes |
None |
None |
DIDENTERBACKGROUNDAPP_DIDENTERBACKGROUND(
SDL_EVENT_DID_ENTER_BACKGROUND) |
Yes |
None |
None |
WILLENTERFOREGROUNDAPP_WILLENTERFOREGROUND(
SDL_EVENT_WILL_ENTER_FOREGROUND) |
Yes |
None |
None |
DIDENTERFOREGROUNDAPP_DIDENTERFOREGROUND(
SDL_EVENT_DID_ENTER_FOREGROUND) |
Yes |
None |
None |
LOCALECHANGED(
SDL_EVENT_LOCALE_CHANGED) |
No |
None |
None |
SYSTEMTHEMECHANGED(
SDL_EVENT_SYSTEM_THEME_CHANGED) |
No |
None |
Not in pygame-ce. |
CLIPBOARDUPDATE(
SDL_EVENT_CLIPBOARD_UPDATE) |
No |
None |
None |
Display Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
DISPLAYORIENTATION(
SDL_EVENT_DISPLAY_ORIENTATION) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYADDED(
SDL_EVENT_DISPLAY_ADDED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYREMOVED(
SDL_EVENT_DISPLAY_REMOVED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYMOVED(
SDL_EVENT_DISPLAY_MOVED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYDESKTOPMODECHANGED(
SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYCURRENTMODECHANGED(
SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYCONTENTSCALECHANGED(
SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
DISPLAYUSABLEBOUNDSCHANGED(
SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED) |
No |
display_index: intdata1: intdata2: int |
Not in pygame-ce. |
display_index is SDL's id for the display, which is not necessarily its
position in the list of displays.
Window Events
Every window event has the fields data1: int, data2: int, and
window: Window | None. The meaning of data1 and data2 depends
on the event, as described by SDL; the Fields column lists other fields.
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
WINDOWSHOWN(
SDL_EVENT_WINDOW_SHOWN) |
Yes |
None |
None |
WINDOWHIDDEN(
SDL_EVENT_WINDOW_HIDDEN) |
Yes |
None |
None |
WINDOWEXPOSED(
SDL_EVENT_WINDOW_EXPOSED) |
Yes |
None |
None |
WINDOWMOVED(
SDL_EVENT_WINDOW_MOVED) |
Yes |
x: inty: int(the window's new position)
|
None |
WINDOWRESIZEDWINDOWSIZECHANGED(
SDL_EVENT_WINDOW_RESIZED) |
Yes |
x: inty: int(the window's new size)
|
|
WINDOWPIXELSIZECHANGED(
SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) |
Yes |
x: inty: int(the window's new size in pixels)
|
Not in pygame-ce. The size in pixels can differ from the size
|
WINDOWMETALVIEWRESIZED(
SDL_EVENT_WINDOW_METAL_VIEW_RESIZED) |
Yes |
None |
Not in pygame-ce. |
WINDOWMINIMIZED(
SDL_EVENT_WINDOW_MINIMIZED) |
Yes |
None |
None |
WINDOWMAXIMIZED(
SDL_EVENT_WINDOW_MAXIMIZED) |
Yes |
None |
None |
WINDOWRESTORED(
SDL_EVENT_WINDOW_RESTORED) |
Yes |
None |
None |
WINDOWMOUSEENTERWINDOWENTER(
SDL_EVENT_WINDOW_MOUSE_ENTER) |
Yes |
None |
|
WINDOWMOUSELEAVEWINDOWLEAVE(
SDL_EVENT_WINDOW_MOUSE_LEAVE) |
Yes |
None |
|
WINDOWFOCUSGAINED(
SDL_EVENT_WINDOW_FOCUS_GAINED) |
Yes |
None |
None |
WINDOWFOCUSLOST(
SDL_EVENT_WINDOW_FOCUS_LOST) |
Yes |
None |
None |
WINDOWCLOSEREQUESTEDWINDOWCLOSE(
SDL_EVENT_WINDOW_CLOSE_REQUESTED) |
Yes |
None |
|
WINDOWHITTEST(
SDL_EVENT_WINDOW_HIT_TEST) |
Yes |
None |
None |
WINDOWICCPROFCHANGED(
SDL_EVENT_WINDOW_ICCPROF_CHANGED) |
Yes |
None |
None |
WINDOWDISPLAYCHANGED(
SDL_EVENT_WINDOW_DISPLAY_CHANGED) |
Yes |
|
|
WINDOWDISPLAYSCALECHANGED(
SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED) |
Yes |
None |
Not in pygame-ce. |
WINDOWSAFEAREACHANGED(
SDL_EVENT_WINDOW_SAFE_AREA_CHANGED) |
Yes |
None |
Not in pygame-ce. |
WINDOWOCCLUDED(
SDL_EVENT_WINDOW_OCCLUDED) |
Yes |
None |
Not in pygame-ce. |
WINDOWENTERFULLSCREEN(
SDL_EVENT_WINDOW_ENTER_FULLSCREEN) |
Yes |
None |
Not in pygame-ce. |
WINDOWLEAVEFULLSCREEN(
SDL_EVENT_WINDOW_LEAVE_FULLSCREEN) |
Yes |
None |
Not in pygame-ce. |
WINDOWDESTROYED(
SDL_EVENT_WINDOW_DESTROYED) |
Yes |
None |
Not in pygame-ce. |
WINDOWHDRSTATECHANGED(
SDL_EVENT_WINDOW_HDR_STATE_CHANGED) |
Yes |
None |
Not in pygame-ce. |
pygame-ce's WINDOWTAKEFOCUS has no SDL 3 equivalent, and is not
available. pygame-ce's window events have only the fields listed in the
pygame-ce documentation, not data1 and data2.
Keyboard and Text Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
KEYDOWN(
SDL_EVENT_KEY_DOWN) |
Yes |
key: intmod: intscancode: intunicode: strrepeat: boolwindow: Window | None |
While text input is active, |
KEYUP(
SDL_EVENT_KEY_UP) |
Yes |
key: intmod: intscancode: intunicode: strrepeat: boolwindow: Window | None |
|
TEXTEDITING(
SDL_EVENT_TEXT_EDITING) |
Yes |
text: strstart: intlength: intwindow: Window | None |
|
TEXTINPUT(
SDL_EVENT_TEXT_INPUT) |
Yes |
text: strwindow: Window | None |
|
TEXTEDITINGCANDIDATES(
SDL_EVENT_TEXT_EDITING_CANDIDATES) |
Yes |
candidates: list[str]selected: inthorizontal: boolwindow_id: intwindow: Window | None |
Not in pygame-ce. |
KEYMAPCHANGED(
SDL_EVENT_KEYMAP_CHANGED) |
Yes |
None |
None |
KEYBOARDADDED(
SDL_EVENT_KEYBOARD_ADDED) |
No |
|
Not in pygame-ce. |
KEYBOARDREMOVED(
SDL_EVENT_KEYBOARD_REMOVED) |
No |
|
Not in pygame-ce. |
SCREENKEYBOARDSHOWN(
SDL_EVENT_SCREEN_KEYBOARD_SHOWN) |
No |
None |
Not in pygame-ce. |
SCREENKEYBOARDHIDDEN(
SDL_EVENT_SCREEN_KEYBOARD_HIDDEN) |
No |
None |
Not in pygame-ce. |
Mouse Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
MOUSEMOTION(
SDL_EVENT_MOUSE_MOTION) |
Yes |
pos: (float, float)rel: (float, float)buttons: (int, int, int)which: inttouch: boolwindow: Window | None |
|
MOUSEBUTTONDOWN(
SDL_EVENT_MOUSE_BUTTON_DOWN) |
Yes |
button: intpos: (float, float)which: inttouch: boolclicks: intwindow: Window | None |
|
MOUSEBUTTONUP(
SDL_EVENT_MOUSE_BUTTON_UP) |
Yes |
button: intpos: (float, float)which: inttouch: boolclicks: intwindow: Window | None |
As for |
MOUSEWHEEL(
SDL_EVENT_MOUSE_WHEEL) |
Yes [1] |
which: intx: floaty: floatprecise_x: floatprecise_y: floatflipped: boolpos: (float, float)touch: boolwindow: Window | None |
|
MOUSEADDED(
SDL_EVENT_MOUSE_ADDED) |
No |
|
Not in pygame-ce. |
MOUSEREMOVED(
SDL_EVENT_MOUSE_REMOVED) |
No |
|
Not in pygame-ce. |
touch is True when SDL synthesized a mouse event from a touch, as in
pygame-ce.
Joystick Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
JOYSTICKAXISMOTIONJOYAXISMOTION(
SDL_EVENT_JOYSTICK_AXIS_MOTION) |
Yes [2] |
joy: intinstance_id: intaxis: intvalue: float |
|
JOYSTICKBALLMOTIONJOYBALLMOTION(
SDL_EVENT_JOYSTICK_BALL_MOTION) |
Yes [2] |
joy: intinstance_id: intball: intrel: (int, int) |
|
JOYSTICKHATMOTIONJOYHATMOTION(
SDL_EVENT_JOYSTICK_HAT_MOTION) |
Yes [2] |
joy: intinstance_id: inthat: intvalue: (int, int) |
|
JOYSTICKBUTTONDOWNJOYBUTTONDOWN(
SDL_EVENT_JOYSTICK_BUTTON_DOWN) |
Yes [2] |
joy: intinstance_id: intbutton: int |
|
JOYSTICKBUTTONUPJOYBUTTONUP(
SDL_EVENT_JOYSTICK_BUTTON_UP) |
Yes [2] |
joy: intinstance_id: intbutton: int |
|
JOYSTICKADDEDJOYDEVICEADDED(
SDL_EVENT_JOYSTICK_ADDED) |
Yes [2] |
which: intdevice_index: intinstance_id: intguid: str |
|
JOYSTICKREMOVEDJOYDEVICEREMOVED(
SDL_EVENT_JOYSTICK_REMOVED) |
Yes [2] |
which: intinstance_id: int |
|
JOYSTICKBATTERYUPDATED(
SDL_EVENT_JOYSTICK_BATTERY_UPDATED) |
No |
which: intinstance_id: intstate: intpercent: int |
Not in pygame-ce. |
JOYSTICKUPDATECOMPLETE(
SDL_EVENT_JOYSTICK_UPDATE_COMPLETE) |
No |
None |
Not in pygame-ce. |
The value of a hat event is an (x, y) tuple, where x is -1 when
the hat is pushed left and 1 when it is pushed right, and y is 1 when it
is pushed up and -1 when it is pushed down. Each is 0 when the hat is
centered in that direction.
Ren'Py consumes these events itself unless
config.pass_joystick_events is True.
Gamepad Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
GAMEPADAXISMOTIONCONTROLLERAXISMOTION(
SDL_EVENT_GAMEPAD_AXIS_MOTION) |
Yes [3] |
which: intinstance_id: intaxis: intvalue: int |
|
GAMEPADBUTTONDOWNCONTROLLERBUTTONDOWN(
SDL_EVENT_GAMEPAD_BUTTON_DOWN) |
Yes [3] |
which: intinstance_id: intbutton: intstate: bool |
|
GAMEPADBUTTONUPCONTROLLERBUTTONUP(
SDL_EVENT_GAMEPAD_BUTTON_UP) |
Yes [3] |
which: intinstance_id: intbutton: intstate: bool |
|
GAMEPADADDEDCONTROLLERDEVICEADDED(
SDL_EVENT_GAMEPAD_ADDED) |
Yes [3] |
which: intdevice_index: intinstance_id: intguid: str |
|
GAMEPADREMOVEDCONTROLLERDEVICEREMOVED(
SDL_EVENT_GAMEPAD_REMOVED) |
Yes [3] |
which: intinstance_id: int |
|
GAMEPADREMAPPEDCONTROLLERDEVICEREMAPPED(
SDL_EVENT_GAMEPAD_REMAPPED) |
No |
which: intinstance_id: int |
|
GAMEPADTOUCHPADDOWN(
SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN) |
No |
which: intinstance_id: inttouch_id: intfinger_id: intx: floaty: floatpressure: float |
Called |
GAMEPADTOUCHPADMOTION(
SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION) |
No |
which: intinstance_id: inttouch_id: intfinger_id: intx: floaty: floatpressure: float |
Called |
GAMEPADTOUCHPADUP(
SDL_EVENT_GAMEPAD_TOUCHPAD_UP) |
No |
which: intinstance_id: inttouch_id: intfinger_id: intx: floaty: floatpressure: float |
Called |
GAMEPADSENSORUPDATE(
SDL_EVENT_GAMEPAD_SENSOR_UPDATE) |
No |
which: intinstance_id: intsensor: intdata: (float, float, float) |
Called |
GAMEPADUPDATECOMPLETE(
SDL_EVENT_GAMEPAD_UPDATE_COMPLETE) |
No |
None |
Not in pygame-ce. |
GAMEPADSTEAMHANDLEUPDATED(
SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED) |
No |
None |
Not in pygame-ce. |
Ren'Py consumes these events itself, to drive its own gamepad
support, unless config.pass_controller_events is True.
Touch Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
FINGERDOWN(
SDL_EVENT_FINGER_DOWN) |
No |
touch_id: intfinger_id: intx: floaty: floatdx: floatdy: floatpressure: floatwindow: Window | None |
|
FINGERUP(
SDL_EVENT_FINGER_UP) |
No |
As for |
As for |
FINGERMOTION(
SDL_EVENT_FINGER_MOTION) |
No |
As for |
As for |
FINGERCANCELED(
SDL_EVENT_FINGER_CANCELED) |
No |
As for |
Not in pygame-ce. |
PINCHBEGIN(
SDL_EVENT_PINCH_BEGIN) |
No |
scale: floatwindow: Window | None |
Not in pygame-ce. |
PINCHUPDATE(
SDL_EVENT_PINCH_UPDATE) |
No |
scale: floatwindow: Window | None |
Not in pygame-ce. |
PINCHEND(
SDL_EVENT_PINCH_END) |
No |
scale: floatwindow: Window | None |
Not in pygame-ce. |
Touch positions are normalized, from 0.0 to 1.0 across the window.
Drop Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
DROPFILE(
SDL_EVENT_DROP_FILE) |
No |
file: str | Nonex: floaty: floatwindow_id: intwindow: Window | None |
|
DROPTEXT(
SDL_EVENT_DROP_TEXT) |
No |
text: str | Nonefile: str | Nonex: floaty: floatwindow_id: intwindow: Window | None |
|
DROPBEGIN(
SDL_EVENT_DROP_BEGIN) |
No |
file: str | Nonex: floaty: floatwindow_id: intwindow: Window | None |
pygame-ce gives only |
DROPCOMPLETE(
SDL_EVENT_DROP_COMPLETE) |
No |
file: str | Nonex: floaty: floatwindow_id: intwindow: Window | None |
pygame-ce gives only |
DROPPOSITION(
SDL_EVENT_DROP_POSITION) |
No |
file: str | Nonex: floaty: floatwindow_id: intwindow: Window | None |
Not in pygame-ce. |
file is None when SDL gives no file name or text for the event.
Device, Pen, Camera, and Sensor Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
AUDIODEVICEADDED(
SDL_EVENT_AUDIO_DEVICE_ADDED) |
No |
which: intiscapture: bool |
None |
AUDIODEVICEREMOVED(
SDL_EVENT_AUDIO_DEVICE_REMOVED) |
No |
which: intiscapture: bool |
None |
AUDIODEVICEFORMATCHANGED(
SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED) |
No |
which: intiscapture: bool |
Not in pygame-ce. |
SENSORUPDATE(
SDL_EVENT_SENSOR_UPDATE) |
No |
which: intinstance_id: intdata: (float, float, float, float, float, float) |
Not in pygame-ce. |
PENPROXIMITYIN(
SDL_EVENT_PEN_PROXIMITY_IN) |
No |
which: intwindow: Window | None |
Not in pygame-ce. |
PENPROXIMITYOUT(
SDL_EVENT_PEN_PROXIMITY_OUT) |
No |
which: intwindow: Window | None |
Not in pygame-ce. |
PENDOWN(
SDL_EVENT_PEN_DOWN) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: floateraser: booldown: bool |
Not in pygame-ce. |
PENUP(
SDL_EVENT_PEN_UP) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: floateraser: booldown: bool |
Not in pygame-ce. |
PENBUTTONDOWN(
SDL_EVENT_PEN_BUTTON_DOWN) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: floatbutton: intdown: bool |
Not in pygame-ce. |
PENBUTTONUP(
SDL_EVENT_PEN_BUTTON_UP) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: floatbutton: intdown: bool |
Not in pygame-ce. |
PENMOTION(
SDL_EVENT_PEN_MOTION) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: float |
Not in pygame-ce. |
PENAXIS(
SDL_EVENT_PEN_AXIS) |
No |
which: intwindow: Window | Nonepen_state: intx: floaty: floataxis: intvalue: float |
Not in pygame-ce. |
CAMERADEVICEADDED(
SDL_EVENT_CAMERA_DEVICE_ADDED) |
No |
|
Not in pygame-ce. |
CAMERADEVICEREMOVED(
SDL_EVENT_CAMERA_DEVICE_REMOVED) |
No |
|
Not in pygame-ce. |
CAMERADEVICEAPPROVED(
SDL_EVENT_CAMERA_DEVICE_APPROVED) |
No |
|
Not in pygame-ce. |
CAMERADEVICEDENIED(
SDL_EVENT_CAMERA_DEVICE_DENIED) |
No |
|
Not in pygame-ce. |
Render Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
RENDERTARGETSRESETRENDER_TARGETS_RESET(
SDL_EVENT_RENDER_TARGETS_RESET) |
Yes |
None |
None |
RENDERDEVICERESETRENDER_DEVICE_RESET(
SDL_EVENT_RENDER_DEVICE_RESET) |
Yes |
None |
None |
RENDERDEVICELOSTRENDER_DEVICE_LOST(
SDL_EVENT_RENDER_DEVICE_LOST) |
No |
None |
Not in pygame-ce. |
User and Ren'Py Events
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
USEREVENTUSER(
SDL_EVENT_USER) |
Yes |
code: intor the attributes of a posted event
|
None |
|
Yes |
Internal to Ren'Py. |
Not in pygame-ce. |
|
Yes |
Internal to Ren'Py. |
Not in pygame-ce. |
|
Yes |
Internal to Ren'Py. |
Not in pygame-ce. |
|
Yes |
Internal to Ren'Py. |
Not in pygame-ce. |
Types from USEREVENT up are never blocked. An event posted with
pygame.event.post is delivered as the same object, with the attributes
it was created with. pygame.event.register returns a new type, and gives
it the name that event_name() returns. Ren'Py registers TIMEEVENT,
PERIODIC, REDRAW, and EVENTNAME for its own use, so the events it
posts with these types should not be relied on.
Markers and Obsolete Names
These names never identify an event a game receives.
Event |
Default |
Fields |
pygame(-ce) differences |
|---|---|---|---|
NOEVENT(
SDL_EVENT_FIRST) |
n/a |
None |
The type of the event |
DISPLAYFIRSTDISPLAYLASTWINDOWFIRSTWINDOWLAST |
n/a |
None |
The first and last display and window event types. Not in pygame-ce. |
PRIVATE0PRIVATE1PRIVATE2PRIVATE3POLLSENTINELLASTENUMPADDING |
n/a |
None |
Reserved by SDL. Not in pygame-ce. |
DISPLAYEVENTWINDOWEVENTSYSWMEVENTDOLLARGESTUREDOLLARRECORDMULTIGESTURE |
n/a |
None |
SDL 2 event types that SDL 3 removed. These names exist so that code using them still loads, but no event has them as its type. |