Skip to content

spec gamepadbuttondown and gamepadbuttonup events (issue #4) - #15

Closed
cvan wants to merge 1 commit into
w3c:gh-pagesfrom
cvan:button-events
Closed

cvan wants to merge 1 commit into
w3c:gh-pagesfrom
cvan:button-events

Conversation

@cvan

@cvan cvan commented Apr 29, 2015

Copy link
Copy Markdown
Contributor

This is a recommendation to spec the button events that Firefox has implemented: gamepadbuttondown and gamepadbuttonup (there's one other non-standard event, gamepadaxismove, which I've omitted for now).

Per @luser in #4 (comment):

Firefox includes non-standard events that you can enable by flipping a pref (dom.gamepad.non_standard_events.enabled), you'll get GamepadButton{Down,Up} and GamepadAxisMove events.

I think spec'ing the button events would be fairly simple and uncontroversial and solves the most important use case--missing button presses that happen between polls.

It's worth noting that this PR doesn't address the other issues outlined in issue #4: whether to introduce axis and/or button change events (à la keypress vs. keydown+keyup).

This is my first contribution, so apologies in advance if this isn't up to snuff. I'm all ears. Thanks for taking a look!

P.S. I have a local branch where I've grouped the interfaces and events into their own respective sections, so the ToC reads a bit more hierarchically. I can submit later, if folks think it's warranted.

Relevant links

@cvan

cvan commented Sep 18, 2016 •

Copy link
Copy Markdown
Contributor Author

this PR has been open for quite a while. shall we close until we've discussed the pros and cons of polling vs. events?

this has recently come up in #37 (comment) and issue #22

@nondebug

Copy link
Copy Markdown
Collaborator

solves the most important use case--missing button presses that happen between polls.

Gamepad button (and axis) events are also important for applications that do not process inputs locally; i.e., when button and axis state is streamed to a remote service that manages the application state, waiting until rAF time to handle inputs adds a significant amount of input latency. Firing events for these inputs would allow the state to be streamed more quickly after the device is polled.

@nondebug

Copy link
Copy Markdown
Collaborator

gamepadbuttondown and gamepadbuttonup

This assumes that gamepad buttons are digital, but many devices expose buttons with analog values that can change without toggling the button's .pressed state. For instance, analog triggers on Xbox 360 or pressure-sensitive buttons on Dualshock 3. I think a gamepadbuttonmove event would also make sense here, in addition to the down/up transition events.

Comment thread index.html
<p>

<i>More discussion is needed on whether to include events for axis
changes (e.g., <code>gamepadaxismove</code> for whenever the value of

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also consider adding a gamepadbuttonmove event in order to better support gamepads that expose buttons with analog values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, thanks!

Comment thread index.html

</dd>

<dt>readonly attribute GamepadButton button</dt>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firefox's implementation uses a button index instead of a GamepadButton:

gamepadbuttondown { target: Window → /, isTrusted: true, button: 1, gamepad: Gamepad, currentTarget: Window → /, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, composed: false, timeStamp: 1530125797442210 }

I think it would be better to include the button index to make it easier for listeners to know which button was pressed. The GamepadButton can be accessed through the gamepad attribute once we know the index, but it's difficult to determine a button's index from a GamepadButton.

Comment thread index.html

<dd>

The single button attribute provides access to the associated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event is asynchronous, but gamepad data is polled synchronously. This means that the button state in GamepadButton may not match the state as described by the event. For instance, for a gamepadbuttondown event, e.button.pressed may no longer be true if the button was released between the time the event was fired and when it was handled.

This proposal should be modified to indicate if the state in e.button is intended to preserve the button's state when the event was generated or if it should report the current button state.

Comment thread index.html
<i>More discussion is needed on whether to include events for axis
changes (e.g., <code>gamepadaxismove</code> for whenever the value of
an axis changes, or <code>gamepadaxischange</code> for whenever the
active axis changes), etc.</i>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an active axis?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, will remove the part about active; that doesn't make sense. multiple axes could change. perhaps "axis changes" could be detected by higher-level abstractions (content libraries).

Comment thread index.html
User agents implementing this specification must provide a new DOM
event, named <a><code>gamepadbuttondown</code></a>. The
corresponding event MUST be of type
<a href="#gamepadevent-interface"><code>GamepadEvent</code></a>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GamepadButtonEvent

@marcoscaceres

Copy link
Copy Markdown
Member

Is this still a thing that's going to be added to the spec?

@cvan

cvan commented Oct 22, 2018 •

Copy link
Copy Markdown
Contributor Author

Is this still a thing that's going to be added to the spec?

I think there's still interest from web developers in having an event model for button changes (or an improved API for polling).

related: see @nondebug's comment here: #83 (comment)

also see these various issues around polling:

#77 – Fast button presses could get lost
#46 – Arbitrary buffering of API calls is causing issues
#22 – Should spec a buffering/refresh interval model of gamepad data?
#8 – Need to spec liveness of Gamepad objects
#4 – Should fire events instead of using passive model

to answer your question: I hope so. does anyone disagree with the changes proposed in this PR? if so, which API changes might we be able to make so as to sanely surface button (and axis) changes?

@mrmcpowned

mrmcpowned commented May 26, 2020 •

Copy link
Copy Markdown

Has there been any more movement on this? I also think it'd be welcoming to have an event-driven model, but only as an inclusion alongside the polling model as well.

The following question was asked in #22:

With that in mind, I guess my question to you is: do you know any practical examples where lost gamepad events are actually a real problem?

Lost gamepad events can be a real problem when the intended use is for accurate input visualization. A lost frame of data can be reasonable in terms of displaying said data, but an inconsistency between axis values or when two or more buttons were pressed simultaneously is not.

The suggested approach to #4 to remedy such a scenario (the API providing an event subscription strategy for multiple axes/buttons/etc) doesn't account for this kind of scenario because it could create a disconnect between axes and button represented at a fixed point in time due to the asynchronicity.

We could then propose something like onGamepadChange that would subscribe to the entire gamepad, but something like that would feel like a bastardization of the polling strategy, and would that really be better than polling from the start?

It's why I'm not against the inclusion of events, but the removal of polling wouldn't allow for the kind of scenarios I'm depicting. For something like adding gamepads as a form of navigational input for a webpage, events would be the perfect approach since it'd be idiomatic in comparison to other event-driven practices and wouldn't necessarily encounter the kind of issues I mentioned above.

This also isn't a theoretical application either. I run and manage gamepadviewer.com, which does exactly what it says, and the amount of usage is not insignificant, either. According to the getGamepads() feature data, the site ranks at least 34th in the list, so everything I've posited isn't hyperbole.

@marcoscaceres

Copy link
Copy Markdown
Member

closing due to inactivity. We might revive this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants