Input & Actions¶
Pite provides both direct key/mouse polling (pite.held, pite.pressed, pite.released) and project-wide named input actions (pite.action.*) configured in res://input.pite.toml.
Input is pumped on the main thread and is visible inside both _process and _physics_process.
Direct Key & Mouse Polling¶
if pite.held.right:
self.position.x += self.speed * delta
if pite.pressed.space:
self.jump()
if pite.released.mouse_left:
self.release_drag()
pite.held.<key>:Trueon every frame the key or button is held down (continuous movement).pite.pressed.<key>:Trueonly on the single frame the key or button transitions from up to down.pite.released.<key>:Trueonly on the single frame the key or button transitions from down to up.pite.mouse() -> Vec2: Returns the cursor position in screen pixels as aVec2(supports.x,.y, and tuple unpackingx, y = pite.mouse()).pite.screen_to_world((screen_x, screen_y)) -> tuple[float, float]: Transforms screen pixel coordinates to world coordinates using the active camera view.
Deprecated String Calls
String-based input calls such as pite.held("Space") are deprecated and raise TypeError. Always use attribute access (pite.held.space) or named actions (pite.action.held("jump")).
Supported Key Attributes¶
| Category | Attributes |
|---|---|
| Letters | a – z |
| Digits | num0 – num9 |
| Arrows | left, right, up, down |
| Control | space, enter, escape, tab, backspace, shift, ctrl, alt |
| Mouse | mouse_left, mouse_right, mouse_middle |
Named Input Actions¶
Named actions decouple gameplay code from physical keys and support multiple bindings and +-separated modifier chords.
Defining Actions¶
Create res://input.pite.toml in your project root (or edit it via Project Settings → Input Map in the editor):
format_version = 1
[actions]
move_left = ["A", "Left"]
move_right = ["D", "Right"]
move_up = ["W", "Up"]
move_down = ["S", "Down"]
jump = ["Space", "W"]
quick_save = ["Control+S"]
Querying Actions in Python¶
move = pite.action.vector("move_left", "move_right", "move_up", "move_down")
self.position.x += move.x * self.speed * delta
self.position.y += move.y * self.speed * delta
if pite.action.pressed("jump"):
self.velocity.y = -320.0
pite.action.held(name: str) -> bool:Truewhile any binding fornameis held.pite.action.pressed(name: str) -> bool:Trueon the frame any binding fornameis pressed.pite.action.released(name: str) -> bool:Trueon the frame any binding fornameis released.pite.action.axis(negative: str, positive: str) -> float: Returns-1.0,0.0, or1.0.pite.action.vector(left: str, right: str, up: str, down: str) -> Vec2: Returns a 2D directional vector normalized to length1.0on diagonals.
Querying an undefined action returns False / 0.0 (or (0.0, 0.0) for vector) and logs a one-time warning.