Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The events for some gamepad buttons do not work. #3317

Closed
hanekoo opened this issue Dec 19, 2024 · 7 comments · Fixed by #3325
Closed

The events for some gamepad buttons do not work. #3317

hanekoo opened this issue Dec 19, 2024 · 7 comments · Fixed by #3325
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@hanekoo
Copy link

hanekoo commented Dec 19, 2024

In Chrome, the gamepad is recognized with 18 buttons, but the GamepadButtonEvent.Buttons only provides 16 buttons, and the additional two buttons do not trigger events. How can I get events for all the buttons?

@eonarheim
Copy link
Member

@hanekoo Good question! Out of curiosity what gamepad hardware are you using? I want to make sure we add these buttons to excalibur

I think this is a limitation of the current Excalibur implementation, it can't read past 16 without some modification. You might be able to patch the ex.Buttons enum to add the additional numeric values and it might just work.... https://github.com/excaliburjs/Excalibur/blob/main/src/engine/Input/Gamepad.ts#L415

Otherwise I think you might have to reach into the native js gamepad until we fix this in Excalibur. MDN has some good docs here https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API

navigator.getGamepads()

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Dec 28, 2024
@hanekoo
Copy link
Author

hanekoo commented Dec 29, 2024

Thank you for your reply.

I am using a Nintendo Pro controller, and the Home (index 16) and Screenshot (index 17) buttons are missing. A generic gamepad should include 17 buttons.

Here are some documents you can refer to:

I believe the GamepadButtonEvent should provide the button indices from the Gamepad API instead of filtering them out. This would allow for more extensibility and flexibility(To support more types of gamepads).

@eonarheim
Copy link
Member

@hanekoo Awesome, thanks for the info. I totally agree!

I'll see what we can do to make this more extensible, in theory should be low effort to fix. Give me a few days :)

@eonarheim
Copy link
Member

@hanekoo This should be fixed in the latest alpha [email protected]

https://www.npmjs.com/package/excalibur/v/0.31.0-alpha.1327

Thanks again!

@hanekoo
Copy link
Author

hanekoo commented Jan 1, 2025

Happy New Year!
Thank you for the quick fix!

Generally, the 17 common buttons are enough, but it would be even better if the index could be exposed:

class GamepadButtonEvent extends GameEvent<Gamepad> {
    button: Buttons;
    index: number; // Not just when the button is unknown
    value: number;
    self: Gamepad;
    ...
}

For example, the Xbox Elite series controllers have additional PADDLE buttons.
If GamepadButtonEvent exposed the index, I could map the index in my program when dealing with unknown buttons.However, if the button is just unknown without the index, it would be impossible to make the mapping judgment.

@eonarheim
Copy link
Member

@hanekoo Good point! I've made those changes e3d6c92

@hanekoo
Copy link
Author

hanekoo commented Jan 2, 2025

Good job! And [email protected] tested fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants