Firefox Tomorrow

web api interface

XRInputSourceEvent

View on MDN ↗

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 XRInputSourceEvent object whose properties match those provided in the eventInitDict dictionary provided.

Instance properties

  • frame Read only
    • : 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 Read only
    • : 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

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.