pyxen.input

Access real-time input from keyboard, mouse, touchscreen, and gamepads.

input = pyxen.input

See also: Input.


Modules

ModuleDescription
keyboardKeys and text input
mousePosition, movement, buttons
touchesMulti-touch input
gamepadsControllers

The Button Model

Keyboard keys, mouse buttons, and gamepad buttons all use the same Button interface:

button.down
button.pressed
button.released
button.value
PropertyMeaning
downTrue while held
pressedTrue only on the frame it was pressed
releasedTrue only on the frame it was released
valueAnalog 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.


Mini samples

Open from Samples & Tutorials inside Pyxen:

  • keyboard.<key>.pressed — Fires once on the press frame.
  • keyboard.<key>.down — True every frame the key is held.
  • arrow keys — Four-direction movement.
  • input.mouse.pos — Sprite follows the cursor.
  • input.mouse.left.pressed — Spawn a colored dot on every click.
  • input.touches — Render a circle at every active touch (iPad/iPhone).
  • gamepad.left_stick — Drive an entity with the left analog stick.
  • gamepad face buttons — A/B/X/Y light up while held.