XRInputSourceEvent

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers .

WebXR 设备 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 .

构造函数

XRInputSourceEvent()
Creates and returns a new XRInputSourceEvent object whose properties match those provided in the eventInitDict dictionary provided.

特性

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.

方法

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 .
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.

范例

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 */
    }
  }
});
					

规范

规范 状态 Comment
WebXR 设备 API
The definition of 'XRInputSourceEvent' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
XRInputSourceEvent Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2
XRInputSourceEvent() 构造函数 Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2
frame Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2
inputSource Chrome 79 Edge 79 Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 79 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 11.2

图例

完整支持
完整支持
不支持
不支持