Original Xbox Controller API using the node-hid HID device driver
See it in action: https://www.youtube.com/watch?v=oPddaJtveMI
First, you require the module and run listControllers() to get
a list of HID devices that look like an Original Xbox Controller.
The array returned is a filtered version of HID.devices() from the
node-hid module.
Then, you create an XboxController object, which is a subclass of
HID.HID, and subscribe to the values event emitted. Events
will be emitted whenever the state of the controller changes.
var xhc = require('xbox-hid-controller');
var controllers = xhc.listControllers();
console.log(controllers);
var controller = new xhc.XboxController(controllers[0].path);
controller.on('values', function(values) {
console.log(values);
});[ { vendorId: 1118,
productId: 645,
path: 'USB_045e_0285_fd121000',
serialNumber: '',
manufacturer: 'Unknown Third-Party',
product: 'Xbox Controller',
release: 256,
interface: -1 } ]
{ up: 0,
down: 0,
left: 0,
right: 0,
start: 0,
back: 0,
las: 0,
ras: 0,
a: 0,
b: 0,
x: 0,
y: 0,
black: 0,
white: 0,
ltrigger: 0,
rtrigger: 0,
lasX: 896,
lasY: -1228,
rasX: 0,
rasY: 413 }
{ up: 0,
down: 0,
left: 0,
right: 0,
start: 0,
back: 0,
las: 0,
ras: 0,
a: 0,
b: 0,
x: 0,
y: 0,
black: 0,
white: 0,
ltrigger: 0,
rtrigger: 0,
lasX: 1344,
lasY: -1228,
rasX: 0,
rasY: 413 }
...
List all HID devices that look like Xbox Controllers.
product: the name to use to filter the list of HID devices, defaults toXbox Controller
List all HID devices. Same as HID.devices()
Create a new XboxController object that emits values events whenever
the controllers state is changed.
- Event
vaules: emitted whenever the controllers state is changed, contains information about the buttons pressed and axis moved
Because XboxController inherits from HID.HID (node-hid),
you can also subscribe to the events emitted directly by this object.
- Event
error: any possible error with the HID device - Event
data: the raw data buffer from the device, this is parsed for you and emitted in a nicer format in thevaluesevent
Install the module
npm install xbox-hid-controller
To use the tools in the examples/ directory, you must install the dev dependencies from npm
git clone git://github.com/bahamas10/node-xbox-hid-controller.git
cd node-xbox-hid-controller
npm install
npm install -d
You must first install this driver http://xhd.sourceforge.net/ for the original Xbox controller to be recognized by OS X.
NOTE: If you are running Mountain Lion, Mavericks, or above, you need to download this version of the driver specifically for it to work http://macman860.wordpress.com/2013/05/03/xbox-driver-for-mac-os-x-lion/
MIT