The HIDConnectionEvent
interface of the WebHID API
represents HID connection events, and is the event type passed to HID.onconnect
and HID.ondisconnect
when an input report is received.
Event
HIDConnectionEvent
This interface also inherits properties from Event
.
HIDConnectionEvent.device
Read only
Returns the HIDDevice
instance representing the device associated with the connection event.
The following example registers event listeners for connect
and disconnect
events, then prints the HIDDevice.productName
to the console.
navigator. hid. addEventListener ( 'connect' , ( { device} ) => {
console. log ( ` HID connected: ${ device. productName} ` ) ;
} ) ;
navigator. hid. addEventListener ( 'disconnect' , ( { device} ) => {
console. log ( ` HID disconnected: ${ device. productName} ` ) ;
} ) ;