input
pykraken.input Input handling and action binding
At a glance
7 membersReference
PYTHON APIbind
functionbind(name: str, actions: Sequence[InputAction]) -> NoneBind a name to a list of InputActions. Rebinding replaces the previous state, samples currently held buttons, and clears edges without synthesizing a press. Analog axes remain analog-only.
Args
- name (
str) — The identifier for this binding (e.g. "jump"). - actions (
Sequence[InputAction]) — One or more InputActions to bind.
get_axis
functionget_axis(negative: str, positive: str) -> floatGet a 1D axis value based on two opposing input actions.
Args
- negative (
str) — Name of the negative direction action (e.g. "left"). - positive (
str) — Name of the positive direction action (e.g. "right").
Returns
- float — Value in range [-1.0, 1.0] based on input.
get_direction
functionget_direction(up: str, right: str, down: str, left: str) -> Vec2Get a directional vector based on named input actions.
This is typically used for WASD-style or D-pad movement.
Args
- up (
str) — Name of action for upward movement. - right (
str) — Name of action for rightward movement. - down (
str) — Name of action for downward movement. - left (
str) — Name of action for leftward movement.
Returns
- Vec2 — A normalized vector representing the intended direction.
is_just_pressed
functionis_just_pressed(name: str) -> boolCheck whether the aggregate action changed from released to held during the last event.poll(). Queries are read-only; repeated reads return the same result. Both edge queries can be True if a press and release occur within one poll. Controller axes are not considered for this check.
Args
- name (
str) — The name of the bound input.
Returns
- bool — True if pressed this frame only.
is_just_released
functionis_just_released(name: str) -> boolCheck whether the last held binding was released during the last event.poll(). Queries are read-only. Both edge queries can be True within one poll. Controller axes are not considered for this check.
Args
- name (
str) — The name of the bound input.
Returns
- bool — True if released this frame only.
is_pressed
functionis_pressed(name: str) -> boolCheck if the given action is currently being held. Controller axes are not considered for this check.
Args
- name (
str) — The name of the bound input.
Returns
- bool — True if any action bound to the name is pressed.
unbind
functionunbind(name: str) -> NoneUnbind a previously registered input name.
Args
- name (
str) — The binding name to remove.