gilrs 0.3.0

Game Input Library for Rust
Documentation

GilRs - Game Input Library for Rust

build status Crates.io Crates.io

Documentation (master)

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 ID for new gamepads and reuse same ID for gamepads which reconnected
  • Force feedback (rumble)
  • Power information (is gamepad wired, current battery status)

The main repository for project is on GitLab although there is also GitHub mirror. Please use GitLab's issue tracker and merge requests.

This repository contains submodule - after you clone it, don't forget to run git submodule init; git submodule update (or clone with --recursive flag) or you will get compile errors.

Example

[dependencies]
gilrs = "0.3.0"
use gilrs::{Gilrs, Button};

let mut gilrs = Gilrs::new();

// Event loop
loop {
    for (id, event) in gilrs.poll_events() {
        println!("New event from {}: {:?}", id, event);
    }

    if gilrs.gamepad(0).is_btn_pressed(Button::South) {
        println!("Name of gamepad 0: {}", gilrs.gamepad(0).name());
    }
}

Supported features

Input Hotplugging Mappings Force feedback
Linux
Windows (XInput) n/a
Windows (DInput)
OS X
Android

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).

License

This project is licensed under the terms of both the Apache License (Version 2.0) and the MIT license. See LICENSE-APACHE and LICENSE-MIT for details.