gamepads 0.1.4

Library to access information about connected gamepads.
Documentation

CI Docs Crates.io version

gamepads

Rust gamepad input library with a focus on ease of use.

use gamepads::Gamepads;

fn main() {
    let mut gamepads = Gamepads::new();

    loop {
        gamepads.poll();

        for gamepad in gamepads.all() {
            println!("Gamepad id: {:?}", gamepad.id());
            for button in gamepad.all_currently_pressed() {
                println!("Pressed button: {:?}", button);
            }
            println!("Left thumbstick: {:?}", gamepad.left_stick());
            println!("Right thumbstick: {:?}", gamepad.right_stick());
        }

        std::thread::sleep(std::time::Duration::from_millis(500));
   }
}

See the crate documentation and the hello-gamepads example for documentation and sample code.

What it is

  • On desktop this library is implemented on top of gilrs.
  • On web this is implemented on top of the Gamepad API exposed by browsers, including support for haptic feedback / dual rumble.
    • It can be used without wasm-bindgen, allowing it to be used as a macroquad plugin
    • It can be used with wasm-bindgen by activating the features = ["wasm-bindgen"]

How to use as a macroquad plugin

For non-web targets, nothing special needs to be done to use this library with macroquad.

For a web build to work properly, a small javascript plug-in needs to be registered in the page embedding the built wasm file:

<script src="https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js"></script>
<script src="https://fornwall.github.io/gamepads/macroquad-gamepads-0.1.js"></script>
<script>
  load("your-wasm-file.wasm");
</script>

See the hello-gamepads example.

Feedback

Please report any issues found or discuss questions and ideas!