Repository navigation
Conversation
|
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 |
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. |
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. |
| <p> | ||
|
|
||
| <i>More discussion is needed on whether to include events for axis | ||
| changes (e.g., <code>gamepadaxismove</code> for whenever the value of |
There was a problem hiding this comment.
Please also consider adding a gamepadbuttonmove event in order to better support gamepads that expose buttons with analog values.
|
|
||
| </dd> | ||
|
|
||
| <dt>readonly attribute GamepadButton button</dt> |
There was a problem hiding this comment.
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.
|
|
||
| <dd> | ||
|
|
||
| The single button attribute provides access to the associated |
There was a problem hiding this comment.
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.
| <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> |
There was a problem hiding this comment.
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).
| 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> |
|
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 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? |
|
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:
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 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 |
|
closing due to inactivity. We might revive this later. |
This is a recommendation to spec the button events that Firefox has implemented:
gamepadbuttondownandgamepadbuttonup(there's one other non-standard event,gamepadaxismove, which I've omitted for now).Per @luser in #4 (comment):
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
keypressvs.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
dom.gamepad.non_standard_events.enabledinabout:config)