XRSession: inputsourceschange event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Theinputsourceschange event is sent to anXRSession when the set of available WebXR input devices changes.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
addEventListener("inputsourceschange", (event) => { })oninputsourceschange = (event) => { }Event type
AnXRInputSourcesChangeEvent. Inherits fromEvent.
Event properties
In addition to the properties listed below, properties from the parent interface,Event, are available.
addedRead onlyAn array of zero or more
XRInputSourceobjects, each representing an input device which has been recently connected or enabled.removedRead onlyAn array of zero or more
XRInputSourceobjects representing the input devices recently disconnected or disabled.sessionRead onlyThe
XRSessionto which this input source change event is being directed.
Description
>Trigger
Triggered when the set of available WebXR input devices changes.
Use cases
You can use this event to detect newly-available devices or when devices have become unavailable.
Examples
The following example shows how to set up an event handler which usesinputsourceschange events to detect newly-available pointing devices and to load their models in preparation for displaying them in the next animation frame.
xrSession.addEventListener("inputsourceschange", onInputSourcesChange);function onInputSourcesChange(event) { for (const input of event.added) { if (input.targetRayMode === "tracked-pointer") { loadControllerMesh(input); } }}You can also add a handler forinputsourceschange events by setting theoninputsourceschange event handler:
xrSession.oninputsourceschange = onInputSourcesChange;Specifications
| Specification |
|---|
| WebXR Device API> # eventdef-xrsession-inputsourceschange> |
| WebXR Device API> # dom-xrsession-oninputsourceschange> |