files/en-us/web/api/xrsession/inputsourceschange_event/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}{{SecureContext_Header}}
The inputsourceschange event is sent to an {{domxref("XRSession")}} when the set of available WebXR input devices changes.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("inputsourceschange", (event) => { })
oninputsourceschange = (event) => { }
An {{domxref("XRInputSourcesChangeEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("XRInputSourcesChangeEvent")}}
In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available.
Triggered when the set of available WebXR input devices changes.
You can use this event to detect newly-available devices or when devices have become unavailable.
The following example shows how to set up an event handler which uses inputsourceschange 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 for inputsourceschange events by setting the oninputsourceschange event handler:
xrSession.oninputsourceschange = onInputSourcesChange;
{{Specifications}}
{{Compat}}