web api interface
XRInputSourceEvent
Secure context
The 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.
Constructor
XRInputSourceEvent()- : Creates and returns a new
XRInputSourceEventobject whose properties match those provided in theeventInitDictdictionary provided.
- : Creates and returns a new
Instance properties
frameRead only- : An
XRFrameobject 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 theXRFramemethodgetViewerPose()on it; instead, usegetPose().
- : An
inputSourceRead only- : An
XRInputSourceobject indicating which input source generated the input event.
- : An
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
XRSessionwhen the sending input source has fully completed a primary action.
- : Sent to an
selectend- : Sent to an
XRSessionwhen an ongoing primary action ends, or when an input source with an ongoing primary action has been disconnected from the system.
- : Sent to an
selectstart- : Sent to an
XRSessionwhen 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.
- : Sent to an
squeeze- : Sent to an
XRSessionwhen the sending input source has fully completed a primary squeeze action.
- : Sent to an
squeezeend- : Sent to an
XRSessionwhen an ongoing primary squeeze action ends or when an input source with an ongoing primary squeeze action is disconnected.
- : Sent to an
squeezestart- : Sent to an
XRSessionwhen an input source begins its primary squeeze action, indicating that the user has begun to grab, squeeze, or grip the controller.
- : Sent to an
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.