All Projects → Tom32i → gamepad.js

Tom32i / gamepad.js

Licence: MIT license
A simple HTML5 Gamepad handler that provides keyboard-like events for Gamepad sticks and buttons.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
Makefile
30231 projects

Projects that are alternatives of or similar to gamepad.js

ControllerBuddy
Highly advanced game controller mapping
Stars: ✭ 47 (+123.81%)
Mutual labels:  gamepad, xbox-controller
XB1ControllerBatteryIndicator
A tray application that shows a battery indicator for an Xbox-ish controller and gives a notification when the battery level drops to (almost) empty.
Stars: ✭ 536 (+2452.38%)
Mutual labels:  gamepad, xbox-controller
xcloud-keyboard-mouse
Chrome extension for controlling Xbox Cloud Gaming (Project xCloud) using a keyboard and mouse
Stars: ✭ 78 (+271.43%)
Mutual labels:  xbox, xbox-controller
ArduinoXInput AVR
AVR boards package for the ArduinoXInput project
Stars: ✭ 53 (+152.38%)
Mutual labels:  xbox, xbox-controller
Xpadneo
Advanced Linux Driver for Xbox One Wireless Controller (shipped with Xbox One S)
Stars: ✭ 797 (+3695.24%)
Mutual labels:  xbox, gamepad
monpad
A fully-customisable web-based gamepad, designed to be used from smartphones.
Stars: ✭ 34 (+61.9%)
Mutual labels:  gamepad
Nethereum.UI.Wallet.Sample
Cross platform wallet example using Nethereum, Xamarin.Forms and MvvmCross
Stars: ✭ 77 (+266.67%)
Mutual labels:  xbox
xbox-smartglass-core-python
SmartGlass Core protocol python library
Stars: ✭ 69 (+228.57%)
Mutual labels:  xbox
nxdk-rdt
Remote Dev Tool is a tool to remote control an Xbox using memory access and RPC
Stars: ✭ 23 (+9.52%)
Mutual labels:  xbox
fatx-tools
Data recovery tools for FATX drives (XBOX and XBOX 360).
Stars: ✭ 51 (+142.86%)
Mutual labels:  xbox
xone
Linux kernel driver for Xbox One and Xbox Series X|S accessories
Stars: ✭ 636 (+2928.57%)
Mutual labels:  xbox
DualSenseWindows UE4
Unreal Engine 4 port of the Windows API for the PS5 DualSense controller created at Ohjurot/DualSense-Windows
Stars: ✭ 25 (+19.05%)
Mutual labels:  gamepad
bluepad32
Bluetooth gamepad support for the ESP32 (mirror)
Stars: ✭ 117 (+457.14%)
Mutual labels:  gamepad
achievement maker
Generate your own achievements
Stars: ✭ 42 (+100%)
Mutual labels:  xbox
cromwell
A free, legal BIOS replacement for the original Xbox
Stars: ✭ 64 (+204.76%)
Mutual labels:  xbox
HadesVR
The "DIY" SteamVR compatible VR setup made for tinkerers.
Stars: ✭ 88 (+319.05%)
Mutual labels:  controllers
mi-360
Xbox360 controller emulation for Xiaomi Gamepad, with vibration support
Stars: ✭ 118 (+461.9%)
Mutual labels:  gamepad
XbSymbolDatabase
Xbox Symbol Database library
Stars: ✭ 20 (-4.76%)
Mutual labels:  xbox
X360Advance
External Arduino gyroscope & pedals for any Xbox compatible gamepads / Внешний Arduino гироскоп и педали для Xbox совместимых геймпадов
Stars: ✭ 35 (+66.67%)
Mutual labels:  xbox-controller
avaje-http
Controller generation for Javalin, Helidon SE.
Stars: ✭ 23 (+9.52%)
Mutual labels:  controllers

gamepad.js

A simple HTML5 Gamepad handler that provides keyboard-like events for Gamepad sticks and button.

Try it right now in your browser: http://tom32i.github.io/gamepad.js/

Installation:

npm install gamepad.js

Import

HTML:

<script src="gamepad.js"></script>
<script>const { GamepadListener } = gamepad;</script>

ES6:

import { GamepadListener } from 'gamepad.js';

Node:

const { GamepadListener } = require('gamepad.js');

Usage:

const listener = new GamepadListener(/* options*/);
listener.start();

Configuration:

analog: (boolean: default true) Set to false to get fixed value: ex for a stick 0/1/-1. Used to reduce the number of change event triggered if you dont need analog values.

precision: (integer: default 0 (no rounding)) When in analog mode, set the number of number you want after decimal. Used to reduce the muber of event triggered but keep analog values.

deadZone: (float: from 0 to 1) Percent of noise to ignore around 0. Ex: deadZone set to 0.3 will cause stick position of from -0.3 to 0.3 to be considered 0. Stick moves below 30% from default positon won't trigger a change.

Theses options can be set for the whole gamepad:

const listener = new GamepadListener({
    analog: false,
    deadZone: 0.3
});

Or distinctly for sticks and buttons:

const listener = new GamepadListener({
    button: {
        analog: false
    },
    stick: {
        precision: 2,
        deadZone: 0.5
    }
});

Events:

  • `gamepad:connected: When a new gamepad is connected.
  • `gamepad:disconnected: When a gamepad is disconnected.
  • `gamepad:axis: When a gamepad axis changes.
  • `gamepad:{gamepad}:axis: When a specific gamepad axis changes, '{gamepad}' being the numeric index.
  • `gamepad:{gamepad}:axis:{axis}: When a specific axis on a specific gamepad changes, '{axis}' being the numeric index of the axis.
  • `gamepad:button: When a gamepad button changes.
  • `gamepad:{gamepad}:button: When a specific gamepad button changes, '{gamepad}' being the numeric index.
  • `gamepad:{gamepad}:button:{button}: When a specific button on a specific gamepad changes, '{button}' being the numeric index of the button.

Listen for value change on gampads:

listener.on('gamepad:connected',  function (event) {
    /**
     * event:
     *   detail: {
     *       index: 0, // Gamepad index [0-3]
     *       gamepad, // Native Gamepad object
     *   }
     */
});

listener.on('gamepad:disconnected',  function (event) {
    /**
     * event:
     *   detail: {
     *       index: 0,
     *       // Native Gamepad object is no longer available
     *   }
     */
});

listener.on('gamepad:axis', function (event) {
    /**
     * event:
     *   detail: {
     *       index: 0, // Gamepad index [0-3]
     *       stick: 0, // Stick index [0-N]
     *       axis: 1, // Axis index [0-1]
     *       value: -0.34, // Value (float if analog, otherise integer)
     *       gamepad, // Native Gamepad object
     *   }
     */
});

listener.on('gamepad:0:button',  function (event) {
    /**
     * event:
     *   detail: {
     *       index: 2, // Gamepad index [0-3]
     *       button: 4, // Button index [0-N]
     *       value: 0.56, // Value (float if analog, otherise integer)
     *       pressed: true, // Boolean
     *       gamepad, // Native Gamepad object
     *   }
     */
});

listener.on('gamepad:0:button:5',  function (event) {
    /**
     * event:
     *   detail: {
     *       index: 3, // Gamepad index [0-3]
     *       button: 8, // Button index [0-N]
     *       value: 1, // Value (float if analog, otherise integer)
     *       pressed: true, // Boolean
     *       gamepad, // Native Gamepad object
     *   }
     */
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].