Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Support for multiple controllers (and multiple types of controllers) #22

@andyfleming

Description

@andyfleming

It would be great to be able to support 2+ controllers at once.

The HID library can successfully list both devices. We'd need to use the device.path property to differentiate. The value looks something like USB_012a_a11a_12300000.

You can list devices via HID with:

var HID = require('node-hid');
var devices = HID.devices();
console.log(devices);

One potential syntax might look something like:

var GamePad = require('node-gamepad');

var controller1 = new GamePad('logitech/gamepadf310');
controller1.connect();

var controller2 = new GamePad('logitech/gamepadf310');
controller2.connect();

Another syntax we might want to consider is a more dynamic one where we can retrieve all supported controllers.

var GamePad = require('node-gamepad');

var supportedGamePadsForMyGame = [
  'logitech/gamepadf310',
  'ps3/dualshock3'
];

var controllers = GamePad(supportedGamePadsForMyGame);

controllers.forEach(function(controller) {
  controller.connect();
  console.log(controller.type); // output example: "logitech/gamepadf310"
  console.log(controller.num); // output example: 0
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions