6

I am building a NW.js (Node-Webkit) dashboard app which I want to be able to control with a game controller (for example: XBox 360 controller or Logitech controller).

I'm calling the following onready but when I debug its not recognizing any gamepads.

angular.element(document).ready(function() {
if(canGame()) {

    var prompt = "To begin using your gamepad, connect it and press any button!";
    $("#gamepadPrompt").text(prompt);

    $(window).on("gamepadconnected", function() {
        $("#gamepadPrompt").html("Gamepad connected!");
        console.log("connection event");
    });

    $(window).on("gamepaddisconnected", function() {
        console.log("disconnection event");
        $("#gamepadPrompt").text(prompt);
    });

}

});


function canGame() {
    return "getGamepads" in navigator;
}

When I debug the code, it doesn't appear to be detecting any gamepads. I also try:

navigator.webkitGetGamepads()

but it doesn't show any gamepads being detected either.

Has anyone successfully used gamepads with a NW.js app?

I would greatly appreciate some help getting this to work.

  • I'm not sure this question is really related to NW.js at all. The above code seems like it should work, and when tested independently (replacing `angular.element(document).ready with `$(document).ready`, and having an html page with just a div#gamepadPrompt, it works fine (tested on chrome 42.0.x using an XBox 360 controller on OSX 10.10). Is there anymore information you can provide? What browser are you testing in? – Cody Haines May 22 '15 at 07:19
  • Thank you for your response Cody. To be clear, this currently is a nwjs project. There is no browser, just a WebKit instance when I run nw.exe. I am debugging by setting toolbar: true. I will add the project to github when I get back from work. – ITellYeHwat May 22 '15 at 20:17
  • There is a specific issue with node-webkit (nw.js) and Windows 8.1 (and possibly specific to xbox gamepads) where getGamepads() will never return any connected controllers. Your code will work fine with OSX, Windows 7, or if you test in the Google Chrome browser under Windows 8.1. The solution is to install the Windows 7 xbox 360 controller drivers on Windows 8.1. Then everything will work again. Drivers available here: https://www.microsoft.com/hardware/en-au/downloads#gaming – Zachstronaut May 26 '15 at 02:09

1 Answers1

1

I found the answer to my issue. Gamepads are indeed compatible with NW.js. I however, was using an old version (~v0.08).

The code I posted earlier when running with NW.js v0.12.2.