gamepad
stableVirtual gamepad state management for games and simulations. Track button and axis values, apply dead-zones, and query pressed inputs through a GamepadState handle.
use plugin gamepad::{GamepadState.new, set_button, set_axis, …} Functions (11)
- GamepadState.new Creates a new empty gamepad state.
- set_button setbutton records whether a named button is currently pressed.
- set_axis setaxis stores a float axis value (typically -1.0 to 1.0).
- axis_value_with_deadzone Returns the axis value, but returns 0.0 if its absolute value is below the dead-zone threshold set via setdeadzone.
- set_dead_zone Sets or reads the dead-zone threshold used by axisvaluewith_deadzone.
- buttons buttons returns a table of {name: bool} for all registered buttons.
- pressed_buttons Returns a list of names for all buttons that are currently pressed (value true).
- reset Clears all button and axis state, returning the gamepad to an empty initial state.
- button_name Returns the standard name for a button or axis by 0-based index.
- apply_deadzone Stateless utility: returns value if its absolute value exceeds threshold, otherwise returns 0.0.
- total_button_count Returns the number of standard button or axis names defined by the plugin.
Creates a new empty gamepad state.
Creates a new empty gamepad state. Buttons and axes are populated by calling set_button and set_axis.
use plugin gamepad::{GamepadState}
let pad = GamepadState.new()
pad.set_dead_zone(0.1)
setaxis stores a float axis value (typically -1.0 to 1.0).
set_axis stores a float axis value (typically -1.0 to 1.0). axis_value reads the raw stored value without any dead-zone filtering.
use plugin gamepad::{GamepadState}
let pad = GamepadState.new()
pad.set_axis("left_stick_x", 0.8)
pad.set_axis("left_stick_y", -0.3)
print(pad.axis_value("left_stick_x")) // 0.8
Returns the axis value, but returns 0.0 if its absolute value is below the dead-zone threshold set via setdeadzone.
Returns the axis value, but returns 0.0 if its absolute value is below the dead-zone threshold set via set_dead_zone. Use this for movement inputs to avoid drift from a centred stick.
use plugin gamepad::{GamepadState}
let pad = GamepadState.new()
pad.set_dead_zone(0.15)
pad.set_axis("left_stick_x", 0.05) // below threshold
pad.set_axis("left_stick_y", 0.6) // above threshold
print(pad.axis_value_with_deadzone("left_stick_x")) // 0.0
print(pad.axis_value_with_deadzone("left_stick_y")) // 0.6
Sets or reads the dead-zone threshold used by axisvaluewith_deadzone.
Sets or reads the dead-zone threshold used by axis_value_with_deadzone. The threshold is stored as an absolute value.
use plugin gamepad::{GamepadState}
let pad = GamepadState.new()
pad.set_dead_zone(0.12)
print(pad.dead_zone()) // 0.12
Clears all button and axis state, returning the gamepad to an empty initial state.
Clears all button and axis state, returning the gamepad to an empty initial state.
use plugin gamepad::{GamepadState}
let pad = GamepadState.new()
pad.set_button("south", true)
pad.reset()
print(pad.is_pressed("south")) // false
Stateless utility: returns value if its absolute value exceeds threshold, otherwise returns 0.0.
Stateless utility: returns value if its absolute value exceeds threshold, otherwise returns 0.0. Use when you have a raw axis value without a GamepadState instance.
use plugin gamepad::{apply_deadzone}
print(apply_deadzone(0.05, 0.1)) // 0.0
print(apply_deadzone(0.5, 0.1)) // 0.5
print(apply_deadzone(-0.8, 0.1)) // -0.8