Source code for simvx.core.input.events

"""Input binding and event types."""

from __future__ import annotations

from dataclasses import dataclass

from .enums import JoyAxis, JoyButton, Key, MouseButton


[docs] @dataclass class InputBinding: """A single input binding — maps to a key, mouse button, or gamepad input.""" key: Key | None = None mouse_button: MouseButton | None = None joy_button: JoyButton | None = None joy_axis: JoyAxis | None = None joy_axis_positive: bool = True # For splitting an axis into two actions deadzone: float = 0.2
[docs] class InputEventKey: """Keyboard input event with rich metadata.""" __slots__ = ("key", "pressed", "echo", "shift", "ctrl", "alt", "handled") def __init__( self, key: Key, pressed: bool, echo: bool = False, shift: bool = False, ctrl: bool = False, alt: bool = False, ): self.key = key self.pressed = pressed self.echo = echo self.shift = shift self.ctrl = ctrl self.alt = alt self.handled = False
[docs] def __repr__(self) -> str: mods = [] if self.shift: mods.append("Shift") if self.ctrl: mods.append("Ctrl") if self.alt: mods.append("Alt") prefix = "+".join(mods) + "+" if mods else "" action = "pressed" if self.pressed else "released" return f"InputEventKey({prefix}{self.key.name} {action})"
[docs] class InputEventMouse: """Mouse button input event.""" __slots__ = ("button", "pressed", "position", "shift", "ctrl", "alt", "handled") def __init__( self, button: MouseButton, pressed: bool, position: tuple[float, float] = (0.0, 0.0), shift: bool = False, ctrl: bool = False, alt: bool = False, ): self.button = button self.pressed = pressed self.position = position self.shift = shift self.ctrl = ctrl self.alt = alt self.handled = False
[docs] def __repr__(self) -> str: action = "pressed" if self.pressed else "released" return f"InputEventMouse({self.button.name} {action} at {self.position})"