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

Feature Request: Button hold/release events #3

Open
Samutz opened this issue Jan 12, 2020 · 3 comments
Open

Feature Request: Button hold/release events #3

Samutz opened this issue Jan 12, 2020 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Samutz
Copy link

Samutz commented Jan 12, 2020

I was hoping to use this library for a menu that can potentially get pretty long and would like to allow the user to hold directions on the d-pad to navigate it as an alternative to repeatedly tapping the directional button.

This works fine with the analog stick since holding the stick in any direction continuously sends the axis_move event. But holding a directional button only sends the button_press event once.

So I am requesting events to be added to determine when a button is being held and then released.

@Samutz
Copy link
Author

Samutz commented Jan 12, 2020

I realized later on that I could just start an interval on the button_press event to check the button status periodically to check if it's still pressed.

@ArunMichaelDsouza
Copy link
Owner

Hi @Samutz,

This can certainly be done. But since the requestAnimationFrame loop is already listening for button events, maybe we can track and dispatch a hold event as well in the same loop. Let me see what can be done. For now, the setInterval approach should work fine.

@ArunMichaelDsouza ArunMichaelDsouza added enhancement New feature or request good first issue Good for newcomers labels Oct 12, 2020
@tremby
Copy link
Contributor

tremby commented Oct 26, 2020

The spec seems to say there's no decision on whether such events will be added natively to the API (https://w3c.github.io/gamepad/#other-events).

Seems to me a decent implementation would fire both a "pressed" and "down" event when the button is first noticed to be pressed, and after monitoring every frame, if it's no longer pressed an "up" gets fired. Does that sound reasonable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants