-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
54 lines (35 loc) · 1.38 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "HID: connect event"
short-title: connect
slug: Web/API/HID/connect_event
page-type: web-api-event
status:
- experimental
browser-compat: api.HID.connect_event
---
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
The **`connect`** event of the {{domxref("HID")}} interface fires when the user agent connects to a HID device.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("connect", (event) => {});
onconnect = (event) => {};
```
## Event type
A {{domxref("HIDConnectionEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("HIDConnectionEvent")}}
## Event properties
_In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available._
- {{domxref("HIDConnectionEvent.device", "device")}} {{ReadOnlyInline}}
- : The {{domxref("HIDDevice")}} the event is fired for.
## 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 {{domxref("HIDDevice.productName")}}.
```js
navigator.hid.addEventListener("connect", ({ device }) => {
console.log(`HID connected: ${device.productName}`);
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}