FThompson/Gamepads.js

Xbox 360 gamepads - trigger buttons don't work properly

Opened this issue · 4 comments

When using devices that claim to be Xbox 360 controllers, the trigger buttons act as axes, and are incorrectly detected by this software as joysticks. I haven't managed to test with a real one though.

To be specific, using https://gamepad-tester.com/ devices that claim to be an Xbox 360 controller have this layout:

const Xbox360Mapping = {
    Button: {
        BUTTON_BOTTOM: 0,
        BUTTON_RIGHT: 1,
        BUTTON_LEFT: 2,
        BUTTON_TOP: 3,
        BUMPER_LEFT: 4,
        BUMPER_RIGHT: 5,
        // Not applicable as triggers are axes on Xbox 360 controllers
        // TRIGGER_LEFT: 6,
        // TRIGGER_RIGHT: 7,
        BUTTON_CONTROL_LEFT: 6,
        BUTTON_CONTROL_RIGHT: 7,
        BUTTON_JOYSTICK_LEFT: 9,
        BUTTON_JOYSTICK_RIGHT: 10,
        // Not applicable as the dpad uses axes on Xbox 360 controllers
        // D_PAD_UP: 12,
        // D_PAD_BOTTOM: 13,
        // D_PAD_LEFT: 14,
        // D_PAD_RIGHT: 15,
        BUTTON_CONTROL_MIDDLE: 8,
    },

    // negative left and up, positive right and down
    Axis: {
        JOYSTICK_LEFT_HORIZONTAL: 0,
        JOYSTICK_LEFT_VERTICAL: 1,
        JOYSTICK_RIGHT_HORIZONTAL: 3,
        JOYSTICK_RIGHT_VERTICAL: 4,
        JOYSTICK_LEFT: [0, 1],
        JOYSTICK_RIGHT: [3, 4],
        TRIGGER_LEFT: 2,
        TRIGGER_RIGHT: 5,
        D_PAD_HORIZONTAL: 6,
        D_PAD_VERTICAL: 7,
        D_PAD: [6, 7]
    }
};

What about a getBestMapping() function that detects the mapping from the device ID and returns the best values, simulating buttons with axes and vice versa where needed? I could work on a PR

What specific operating system, browser, and specific controller model are you using?

Fundamentally, this result (from both Gamepads.js and gamepad-tester.com) means that the HTML5 gamepad library detects your gamepad as having a non-standard configuration.

For comparison, my official Xbox One and Xbox Series X controllers report as having a standard configuration on all tested OS/browser combinations (Windows 10 / Mac OS X / Ubuntu 18.04, Chrome / Firefox) except Firefox on Ubuntu. With Firefox on Ubuntu, the Xbox One controller reports as the non-standard configuration that you describe.

If I recall correctly, device ID isn't consistently reported, so I'm not sure we can reliably rely on it. A better approach might be to detect device ID alongside various counts of buttons/axes to make a best guess at mapping a non-standard controller to a standard controller. Even then, an incorrect mapping could yield a poor UX.

When I developed this library for my Netflix Controller browser extension, I decided that the best approach to non-standard gamepads would be to allow users to re-map their gamepads as they see fit. I haven't implemented that, but I think barring a surefire way to identify how to re-map a gamepad, the best solution is to provide the user a way to define the mapping themselves.

What specific operating system, browser, and specific controller model are you using?

Fundamentally, this result (from both Gamepads.js and gamepad-tester.com) means that the HTML5 gamepad library detects your gamepad as having a non-standard configuration.

For comparison, my official Xbox One and Xbox Series X controllers report as having a standard configuration on all tested OS/browser combinations (Windows 10 / Mac OS X / Ubuntu 18.04, Chrome / Firefox) except Firefox on Ubuntu. With Firefox on Ubuntu, the Xbox One controller reports as the non-standard configuration that you describe.

If I recall correctly, device ID isn't consistently reported, so I'm not sure we can reliably rely on it. A better approach might be to detect device ID alongside various counts of buttons/axes to make a best guess at mapping a non-standard controller to a standard controller. Even then, an incorrect mapping could yield a poor UX.

When I developed this library for my Netflix Controller browser extension, I decided that the best approach to non-standard gamepads would be to allow users to re-map their gamepads as they see fit. I haven't implemented that, but I think barring a surefire way to identify how to re-map a gamepad, the best solution is to provide the user a way to define the mapping themselves.

Firefox on Ubuntu 20.04, yes. So I assumed this would happen everywhere but if it's browser/OS-specific I guess it's not as much of a problem