Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use gamepads with Node-Webkit (NW.js)?

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.

like image 779
ITellYeHwat Avatar asked May 22 '15 06:05

ITellYeHwat


1 Answers

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.

like image 70
ITellYeHwat Avatar answered Oct 04 '22 04:10

ITellYeHwat