HID: connect event
WebHID APIwindowandworkerexceptshared
WebHID APIwindow_and_worker_except_shared
The connect event of the HID interface fires when the user agent connects to a HID device.
Syntax
Use the event name in addEventListener():
addEventListener("connect", (event) => { })
Alternatively, assign to the event handler property of the interface:
onconnect = (event) => { }
Event type
A HIDConnectionEvent. Inherits from Event.
HIDConnectionEvent
Examples
In the following example an event listener is registered to listen for the connection of a device. The name of the device is then printed to the console using HIDDevice.productName.
navigator.hid.addEventListener("connect", ({ device }) => {
console.log(`HID connected: ${device.productName}`);
});