Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The XRInputSourceEvent()
constructor creates and returns a new XRInputSourceEvent
object describing an event (state change) which has occurred on a WebXR user input device represented by an XRInputSource
.
Syntax
newInputSourceEvent = new XRInputSourceEvent(type, eventInitDict);
Parameters
type
- A
DOMString
indicating which of the input source events the new object will represent. Permitted values are listed under Event types below. eventInitDict
- An object based on the
XRInputSourceEventInit
dictionary which contains the values to assign to the new event's properties.
Return value
A new XRInputSourceEvent
object representing the event described by the given type
and eventInitDict
.
Event types
select
- Sent to an
XRSession
when the sending input source has fully completed a primary action. selectend
- Sent to an
XRSession
when an ongoing primary action ends, or when an input source with an ongoing primary action has been disconnected from the system. selectstart
- Sent to an
XRSession
when an input source begins its primary action, indicating that the user has begun a command-like input, such as pressing a trigger or button, issuing a spoken command, tapping on a touchpad, or the like. squeeze
- Sent to an
XRSession
when the sending input source has fully completed a primary squeeze action. squeezeend
- Sent to an
XRSession
when an ongoing primary squeeze action ends or when an input source with an ongoing primary squeeze action is disconnected. squeezestart
- Sent to an
XRSession
when an input source begins its primary squeeze action, indicating that the user has begun to grab, squeeze, or grip the controller.
Examples
The code below sets up handlers for primary action events in order to determine when the user clicks on (shoots at/pokes at/whatever) objects in the scene.
xrSession.addEventListener("select", event => {
let targetRayPose = event.frame.getPose(event.inputSource.targetRaySpace, myRefSpace);
if (targetRayPose) {
let hit = myHitTest(targetRayPose.transform);
if (hit) {
/* handle the hit */
}
}
});
Specifications
Specification | Status | Comment |
---|---|---|
WebXR Device APIThe definition of 'XRInputSourceEvent' in that specification. | Working Draft | Initial definition. |
Browser compatibility
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
XRInputSourceEvent
|
Chrome
Full support 79 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
Full support 79 |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
Full support 11.2 |
XRInputSourceEvent() constructor
|
Chrome
Full support 79 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
Full support 79 |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
Full support 11.2 |
frame
|
Chrome
Full support 79 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
Full support 79 |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
Full support 11.2 |
inputSource
|
Chrome
Full support 79 |
Edge
Full support 79 |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
Full support 79 |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
Full support 11.2 |
Legend
- Full support
- Full support
- No support
- No support
XRInputSourceEvent() by Mozilla Contributors is licensed under CC-BY-SA 2.5.