XRInputSourceEvent
WebXR Device API
WebXR Device API
The [WebXR Device API](/docs/Web/API/WebXR_Device_API)'s **`XRInputSourceEvent`** interface describes an event which has occurred on a WebXR user input device such as a hand controller, gaze tracking system, or motion tracking system. More specifically, they represent a change in the state of an XRInputSource.
To learn more about handling inputs in a WebXR project, see the article [Inputs and input sources](/docs/Web/API/WebXR_Device_API/Inputs).
## Constructor
- XRInputSourceEvent()
- : Creates and returns a new `XRInputSourceEvent` object whose properties match those provided in the `eventInitDict` dictionary provided.
## Instance properties
- frame
- : An XRFrame object providing the needed information about the event frame during which the event occurred. This frame may have been rendered in the past rather than being a current frame. Because this is an _event_ frame, not an _animation_ frame, you cannot call the XRFrame method getViewerPose() on it; instead, use getPose().
- inputSource
- : An XRInputSource object indicating which input source generated the input event.
## Instance methods
_The `XRInputSourceEvent` interface doesn't define any methods; however, several methods are inherited from the parent interface, Event._
## Event types
- select
- : Sent to an XRSession when the sending input source has fully completed a [primary action](/docs/Web/API/WebXR_Device_API/Inputs#primary_action).
- selectend
- : Sent to an XRSession when an ongoing [primary action](/docs/Web/API/WebXR_Device_API/Inputs#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](/docs/Web/API/WebXR_Device_API/Inputs#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](/docs/Web/API/WebXR_Device_API/Inputs#primary_squeeze_action).
- squeezeend
- : Sent to an XRSession when an ongoing [primary squeeze action](/docs/Web/API/WebXR_Device_API/Inputs#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](/docs/Web/API/WebXR_Device_API/Inputs#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.
```js
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
## Browser compatibility
Cite this
"XRInputSourceEvent". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceEvent JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy