Crate gilrs [−] [src]
GilRs - Game Input Library for Rust
GilRs abstract platform specific APIs to provide unified interfaces for working with gamepads.
Main features:
- Unified gamepad layout - buttons and axes are represented by familiar names
- Support for SDL2 mappings including
SDL_GAMECONTROLLERCONFIG
environment variable which Steam uses - Hotplugging - GilRs will try to assign new IDs for new gamepads and reuse same ID for gamepads which reconnected
- Force feedback (rumble)
- Power information (is gamepad wired, current battery status)
Example
use gilrs::{Gilrs, Button}; let mut gilrs = Gilrs::new(); // Iterate over all connected gamepads for (_id, gamepad) in gilrs.gamepads() { println!("{} is {:?}", gamepad.name(), gamepad.power_info()); } loop { // Examine new events for (id, event) in gilrs.poll_events() { println!("New event from {}: {:?}", id, event); } // You can also use cached gamepad state if gilrs[0].is_btn_pressed(Button::South) { println!("Button South is pressed (XBox - A, PS - X)"); } }Run
Supported features
Input | Hotplugging | Mappings | Force feedback | |
---|---|---|---|---|
Linux | ✓ | ✓ | ✓ | ✓ |
Windows (XInput) | ✓ | ✓ | n/a | ❌ |
Windows (DInput) | ❌ | ❌ | ❌ | ❌ |
OS X | ❌ | ❌ | ❌ | ❌ |
Android | ❌ | ❌ | ❌ | ❌ |
Controller layout
Mappings
GilRs use SDL-compatible controller mappings to fix on Linux legacy drivers that doesn't follow
Linux Gamepad API and to provide
unified button layout for platforms that doesn't make any guarantees about it. The main source
is SDL_GameControllerDB, but library also
support loading mappings from environment variable SDL_GAMECONTROLLERCONFIG
(which Steam
use).
Platform specific notes
Linux
On Linux, GilRs read (and write, in case of force feedback) directly from appropriate
/dev/input/event*
file. This mean that user have to have read and write access to this file.
On most distros it shouldn't be a problem, but if it is, you will have to create udev rule.
To build GilRs, you will need pkg-config and libudev .pc file. On some
distributions this file is packaged in separate archive (for example libudev-dev
in Debian).
Modules
ff |
Force feedback module |
Structs
ConnectedGamepadsIterator |
Iterator over all connected gamepads. |
EventIterator |
Iterator over gamepads events |
Gamepad |
Represents game controller. |
GamepadState |
Cached state of gamepad's buttons and axes. |
Gilrs |
Main object responsible of managing gamepads. |
Enums
Axis |
Gamepad's elements which state can be represented by |
Button |
Gamepad's elements which state can be represented by |
Event |
Gamepad event. |
PowerInfo |
State of device's power supply. |
Status |
Status of gamepad's connection. |