Hands
simple gamepad API for browser.
Install
$ npm install hands
Usage
importing and instantiation:
var Hands = ; // get all connected controllers var hands = ;
reading updated values of connected controllers:
// main animation loop { // welcome new controller connections hands; // update all connected controllers hands; // print new values hands; // continue updating window; } // begin updating window;
setting reaction handlers on value updates
// initialize array of values we would like to control var X = // register reaction handlers for each connected controller hands; // main animation loop { // update all connected controllers and call // all attached reaction handlers hands; // // continue updating window; } // begin updating window;
attaching an onConnection/onDisconnection callback to a new controller connection:
// initialize an empty map of objects var A = {} // set onConnection callback hands;
Notes
Since this library relies on the experimental GamePad API, it is only supported by a subset of modern browsers (Chrome >35.0, Firefox >29.0, Opera >22.0). Please check the Compatibility for more details.