pyxen.input
Access real-time input from keyboard, mouse, touchscreen, and gamepads.
input = pyxen.input
See also: Input.
Modules
| Module | Description |
|---|---|
keyboard | Keys and text input |
mouse | Position, movement, buttons |
touches | Multi-touch input |
gamepads | Controllers |
The Button Model
Keyboard keys, mouse buttons, and gamepad buttons all use the same Button interface:
button.down
button.pressed
button.released
button.value
| Property | Meaning |
|---|---|
down | True while held |
pressed | True only on the frame it was pressed |
released | True only on the frame it was released |
value | Analog value (0.0 → 1.0) |
Frame-Based Behavior
Input is evaluated per frame.
pressed and released are only true for one frame, then reset automatically.
if input.keyboard.space.pressed:
player.jump()
For continuous behavior:
if input.keyboard.space.down:
charge_power()
Quick Examples
Keyboard Movement
kbd = input.keyboard
if kbd.left.down:
player.x -= 1
if kbd.right.down:
player.x += 1
Mouse Click
mouse = input.mouse
if mouse.left.pressed:
x, y = mouse.pos
spawn_explosion(x, y)
Touch Input
for t in input.touches:
if t.started:
print("Touch at", t.pos)
Gamepad Analog Movement
pad = input.gamepads[0]
if pad.connected:
x, y = pad.left_stick
player.x += x * 2
player.y += y * 2
Read-Only Safety
All input objects are read-only. Input state is managed by the engine.