Coder Social home page Coder Social logo

arvamer / gilrs Goto Github PK

View Code? Open in Web Editor NEW
139.0 7.0 8.0 1.07 MB

Game Input Library for Rust - Mirror of https://gitlab.com/gilrs-project/gilrs

License: Apache License 2.0

Rust 99.30% HTML 0.26% PowerShell 0.22% Shell 0.22%
gamepad input joystick rust force-feedback

gilrs's Introduction

GilRs - Game Input Library for Rust

pipeline status Crates.io Documentation Minimum rustc version

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 project's main repository is on GitLab although there is also a 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.10.3"
use gilrs::{Gilrs, Button, Event};

let mut gilrs = Gilrs::new().unwrap();

// Iterate over all connected gamepads
for (_id, gamepad) in gilrs.gamepads() {
    println!("{} is {:?}", gamepad.name(), gamepad.power_info());
}

let mut active_gamepad = None;

loop {
    // Examine new events
    while let Some(Event { id, event, time }) = gilrs.next_event() {
        println!("{:?} New event from {}: {:?}", time, id, event);
        active_gamepad = Some(id);
    }

    // You can also use cached gamepad state
    if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
        if gamepad.is_pressed(Button::South) {
            println!("Button South is pressed (XBox - A, PS - X)");
        }
    }
}

Supported features

Input Hotplugging Force feedback
Linux/BSD (evdev)
Windows (XInput)
OS X
Wasm n/a
Android

Platform specific notes

Linux/BSD (evdev)

With evdev, 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. On FreeBSD generic HID gamepads use hgame(4) and special use Linux driver via webcamd.

To build GilRs, you will need pkg-config and libudev .pc file. On some distributions this file is packaged in separate archive (e.g., libudev-dev in Debian, libudev-devd in FreeBSD).

Wasm

Wasm implementation uses stdweb, or wasm-bindgen with the wasm-bindgen feature. For stdweb, you will need cargo-web to build gilrs for wasm32-unknown-unknown. For wasm-bindgen, you will need the wasm-bindgen cli or a tool like wasm-pack. Unlike other platforms, events are only generated when you call Gilrs::next_event().

See ./gilrs/examples/wasm/README.md for running the examples using Wasm.

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.

gilrs's People

Contributors

aleksijuvani avatar arvamer avatar batonius avatar burtonageo avatar cleancut avatar coolreader18 avatar evilpie avatar fornwall avatar frankkkkk avatar gui1117 avatar jbeich avatar jnises avatar jtakakura avatar kernelfreeze avatar kuviman avatar marijns95 avatar metiulekm avatar mstrodl avatar msvbg avatar paul-hansen avatar photex avatar r3dp1xl avatar repi avatar rtzoeller avatar rukai avatar ryanisaacg avatar smoli avatar snheath avatar theunkn0wn1 avatar torkleyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.