Comprehensive reference for event attributes in PyKraken, detailing available events and their associated attributes.
type attribute containing the SDL event type constantAttributeErrorEventType enum, which is exported to the module level for convenienceimport pykraken as kn
...
while kn.window.is_open():
for event in kn.event.poll():
if event.type == kn.KEY_DOWN:
print(f"Key pressed: {event.key}, scancode: {event.scan}")
print(f"Modifiers: {event.mod}, Repeat: {event.repeat}")
elif event.type == kn.MOUSE_BUTTON_DOWN:
print(f"Mouse button {event.button} clicked at ({event.x}, {event.y})")
print(f"Click count: {event.clicks}")
elif event.type == kn.MOUSE_WHEEL:
print(f"Mouse wheel: dx={event.x}, dy={event.y}")
print(f"Mouse position: ({event.mouse_x}, {event.mouse_y})")
elif event.type == kn.GAMEPAD_BUTTON_DOWN:
print(f"Gamepad {event.which} button {event.button} pressed")
QUIT
TERMINATING
LOW_MEMORY
WILL_ENTER_BACKGROUND
DID_ENTER_BACKGROUND
WILL_ENTER_FOREGROUND
DID_ENTER_FOREGROUND
LOCALE_CHANGED
SYSTEM_THEME_CHANGED
No attributes.
DISPLAY_ORIENTATION
DISPLAY_ADDED
DISPLAY_REMOVED
DISPLAY_MOVED
DISPLAY_DESKTOP_MODE_CHANGED
DISPLAY_CURRENT_MODE_CHANGED
DISPLAY_CONTENT_SCALE_CHANGED
DISPLAY_USABLE_BOUNDS_CHANGED
display_id (int): The display that was affecteddata1 (int): Event-specific datadata2 (int): Event-specific dataWINDOW_SHOWN
WINDOW_HIDDEN
WINDOW_EXPOSED
WINDOW_MOVED
WINDOW_RESIZED
WINDOW_MINIMIZED
WINDOW_MAXIMIZED
WINDOW_RESTORED
WINDOW_MOUSE_ENTER
WINDOW_MOUSE_LEAVE
WINDOW_FOCUS_GAINED
WINDOW_FOCUS_LOST
WINDOW_CLOSE_REQUESTED
WINDOW_HIT_TEST
WINDOW_ICCPROF_CHANGED
WINDOW_DISPLAY_CHANGED
WINDOW_DISPLAY_SCALE_CHANGED
WINDOW_SAFE_AREA_CHANGED
WINDOW_OCCLUDED
WINDOW_ENTER_FULLSCREEN
WINDOW_LEAVE_FULLSCREEN
WINDOW_DESTROYED
WINDOW_HDR_STATE_CHANGED
window_id (int): The window that was affecteddata1 (int): Event-specific data (e.g., new x position for MOVED, new width for RESIZED)data2 (int): Event-specific data (e.g., new y position for MOVED, new height for RESIZED)KEY_DOWN
KEY_UP
which (int): Keyboard device IDkey (Keycode): Virtual key code (e.g., K_SPACE)scan (Scancode): Physical key scancode (e.g., S_SPACE)repeat (bool): True if this is a key repeat eventmod (int): Keyboard modifier state (Shift, Ctrl, Alt, etc.)window_id (int): The window with keyboard focusTEXT_EDITING
window_id (int): The window with keyboard focustext (str): The editing textstart (int): Start position of selected editing textlength (int): Length of selected editing textTEXT_INPUT
window_id (int): The window with keyboard focustext (str): The input textTEXT_EDITING_CANDIDATES
window_id (int): The window with keyboard focuscandidates (list[str]): List of candidate stringsnum_candidates (int): Number of candidatesselected_candidate (int): Index of the selected candidatehorizontal (bool): True if candidates should be displayed horizontallypadding1 (int): Reservedpadding2 (int): Reservedpadding3 (int): ReservedKEYMAP_CHANGED
No attributes.
KEYBOARD_ADDED
KEYBOARD_REMOVED
which (int): Keyboard device IDSCREEN_KEYBOARD_SHOWN
SCREEN_KEYBOARD_HIDDEN
No attributes.
MOUSE_MOTION
which (int): Mouse device IDx (float): Mouse X positiony (float): Mouse Y positionxrel (float): Relative motion in X directionyrel (float): Relative motion in Y directionstate (int): Button state during motionwindow_id (int): The window with mouse focusMOUSE_BUTTON_DOWN
MOUSE_BUTTON_UP
which (int): Mouse device IDbutton (MouseButton): Mouse button that was pressed/releasedx (float): Mouse X position when button was pressed/releasedy (float): Mouse Y position when button was pressed/releasedclicks (int): Click count (1 = single click, 2 = double click, etc.)window_id (int): The window with mouse focusMOUSE_WHEEL
which (int): Mouse device IDx (float): Horizontal scroll amount (positive = right, negative = left)y (float): Vertical scroll amount (positive = away from user, negative = toward user)intx (int): Integer horizontal scroll amountinty (int): Integer vertical scroll amountwindow_id (int): The window with mouse focusmouse_x (float): Mouse X position when wheel was scrolledmouse_y (float): Mouse Y position when wheel was scrolledMOUSE_ADDED
MOUSE_REMOVED
which (int): Mouse device IDGAMEPAD_AXIS_MOTION
which (int): Gamepad instance IDaxis (int): The gamepad axis (see GamepadAxis enum)value (int): Axis value (range: -32768 to 32767)GAMEPAD_BUTTON_DOWN
GAMEPAD_BUTTON_UP
which (int): Gamepad instance IDbutton (GamepadButton): The gamepad button that was pressed/releasedGAMEPAD_ADDED
GAMEPAD_REMOVED
GAMEPAD_REMAPPED
GAMEPAD_UPDATE_COMPLETE
GAMEPAD_STEAM_HANDLE_UPDATED
which (int): Gamepad instance IDGAMEPAD_TOUCHPAD_DOWN
GAMEPAD_TOUCHPAD_MOTION
GAMEPAD_TOUCHPAD_UP
which (int): Gamepad instance IDtouchpad (int): The touchpad index on the gamepadfinger (int): The finger index on the touchpadx (float): Normalized X position (0.0 to 1.0)y (float): Normalized Y position (0.0 to 1.0)pressure (float): Normalized pressure (0.0 to 1.0)GAMEPAD_SENSOR_UPDATE
which (int): Gamepad instance IDsensor (int): The sensor type (see SDL_SensorType)data (list[float]): Sensor data (3 float values)timestamp (int): Sensor timestamp in microsecondsFINGER_DOWN
FINGER_UP
FINGER_MOTION
FINGER_CANCELED
touch_id (int): The touch device IDfinger_id (int): The finger IDx (float): Normalized X position (0.0 to 1.0)y (float): Normalized Y position (0.0 to 1.0)dx (float): Normalized change in X directiondy (float): Normalized change in Y directionpressure (float): Normalized pressure (0.0 to 1.0)window_id (int): The window underneath the fingerPINCH_BEGIN
PINCH_UPDATE
PINCH_END
window_id (int): The window with pinch gesturescale (float): Pinch scale factorPEN_PROXIMITY_IN
PEN_PROXIMITY_OUT
which (int): Pen device IDPEN_DOWN
PEN_UP
which (int): Pen device IDx (float): Pen X positiony (float): Pen Y positioneraser (bool): True if the eraser tip is being usedPEN_BUTTON_DOWN
PEN_BUTTON_UP
which (int): Pen device IDbutton (int): Button index that was pressed/releasedx (float): Pen X positiony (float): Pen Y positionPEN_MOTION
which (int): Pen device IDx (float): Pen X positiony (float): Pen Y positionPEN_AXIS
which (int): Pen device IDx (float): Pen X positiony (float): Pen Y positionaxis (int): Axis index that changed (see PenAxis enum)value (float): Axis valueCLIPBOARD_UPDATE
num_mime_types (int): Number of MIME types availablemime_types (list[str]): List of MIME type stringsDROP_FILE
DROP_TEXT
data (str): The file path or text that was droppedx (float): X position where drop occurredy (float): Y position where drop occurredDROP_BEGIN
DROP_COMPLETE
DROP_POSITION
x (float): X position of the dropy (float): Y position of the dropAUDIO_DEVICE_ADDED
AUDIO_DEVICE_REMOVED
AUDIO_DEVICE_FORMAT_CHANGED
which (int): Audio device IDrecording (bool): True if this is a recording device, False for playbackSENSOR_UPDATE
which (int): Sensor instance IDdata (list[float]): Sensor data (6 float values)CAMERA_DEVICE_ADDED
CAMERA_DEVICE_REMOVED
CAMERA_DEVICE_APPROVED
CAMERA_DEVICE_DENIED
which (int): Camera device IDRENDER_TARGETS_RESET
RENDER_DEVICE_RESET
RENDER_DEVICE_LOST
No attributes.