HTML5 Gamepad API on Chrome

前端 未结 3 681
一生所求
一生所求 2021-02-15 15:15

I\'m using Chrome (Version 19.0.1084.46). I enabled the Gamepad API in chrome://flags. I plugged in some game pads, but navigator.webkitGamepads is always an array

3条回答
  •  梦谈多话
    2021-02-15 15:40

    This didn't work for me but maybe it helps you? Pulled from here.

    function updateStatus() {
        window.webkitRequestAnimationFrame(updateStatus);
    
        var gamepads = navigator.webkitGamepads;
    
        var data = '';
        for (var padindex = 0; padindex < gamepads.length; ++padindex)
        {
            var pad = gamepads[padindex];
            if (!pad) continue;
            data += '
    ' + pad.index + ": " + pad.id + "
    "; for (var i = 0; i < pad.buttons.length; ++i) data += "button" + i + ": " + pad.buttons[i] + "
    "; for (var i = 0; i < pad.axes.length; ++i) data += "axis" + i + ": " + pad.axes[i] + "
    "; } document.body.innerHTML = data; } window.webkitRequestAnimationFrame(updateStatus);

    Or as a hard alternative, there's the Javascript Joystick Plug-in (demo here) but I don't think that works in Linux.

提交回复
热议问题