Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fornwall/gamepads
Rust gamepad input library with a focus on ease of use.
https://github.com/fornwall/gamepads
gamedev gamepad input rust webassembly
Last synced: 3 months ago
JSON representation
Rust gamepad input library with a focus on ease of use.
- Host: GitHub
- URL: https://github.com/fornwall/gamepads
- Owner: fornwall
- License: apache-2.0
- Created: 2023-09-14T18:20:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-26T20:57:47.000Z (over 1 year ago)
- Last Synced: 2024-09-15T05:39:28.157Z (4 months ago)
- Topics: gamedev, gamepad, input, rust, webassembly
- Language: Rust
- Homepage:
- Size: 51.8 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-quads - gamepads - to access gamepads. (Libraries / Libraries: Plugins)
README
[![CI](https://github.com/fornwall/gamepads/actions/workflows/ci.yml/badge.svg)](https://github.com/fornwall/gamepads/actions/workflows/ci.yml)
[![Docs](https://docs.rs/gamepads/badge.svg)](https://docs.rs/gamepads/)
[![Crates.io version](https://img.shields.io/crates/v/gamepads.svg)](https://crates.io/crates/gamepads)# gamepads
Rust gamepad input library with a focus on ease of use. Supports haptic feedback (dual rumble / vibrations) on the web, and can be used as a [macroquad plugin](https://github.com/fornwall/gamepads#how-to-use-as-a-macroquad-plugin).```rust
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](https://docs.rs/gamepads/latest/gamepads/) and the [examples](https://github.com/fornwall/gamepads/tree/main/examples/) for documentation and sample code.
## What it is
- On desktop this library is implemented on top of [gilrs](https://crates.io/crates/gilrs).
- On web this is implemented on top of the [Gamepad API](https://www.w3.org/TR/gamepad/) exposed by browsers, including support for haptic feedback (aka "dual rumble" or "force feedback").
- It can be used in a `wasm-bindgen`-using project without any setup necessary.
- It can be used without `wasm-bindgen` (by specifying `default-features = false`), allowing it to be used as a `macroquad` plugin (see more below) or in a direct wasm build ([example](https://github.com/fornwall/gamepads/tree/main/examples/gamepads-wasm-direct)).## How to use as a macroquad plugin
For non-web targets, nothing special needs to be done to use this library with [macroquad](https://github.com/not-fl3/macroquad). But for a web build to work properly, two things needs to be done.First, since `macroquad` does not use `wasm-bindgen`, that feature in `gamepads` needs to be turned off by setting `default-features = false`:
```toml
gamepads = { version = "*", default-features = false }
```Second, a javascript plug-in ([source](https://github.com/fornwall/gamepads/blob/main/js/gamepads-src-0.1.js)) needs to be registered in the page embedding the built wasm file:
```html
load("your-wasm-file.wasm");
```
See the [gamepads-macroquad](https://github.com/fornwall/gamepads/tree/main/examples/gamepads-macroquad) example.
# Feedback
Please [report any issues found](https://github.com/fornwall/gamepads/issues) or [discuss questions and ideas](https://github.com/fornwall/gamepads/discussions)!