HIDDevice: inputreport event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Web Workers, except for Shared Web Workers.

The inputreport event of the HIDDevice interface fires when a new report is received from the HID device.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("inputreport", (event) => { })

oninputreport = (event) => { }

Event type

An HIDInputReportEvent. Inherits from Event.

Event HIDInputReportEvent

Event properties

This interface also inherits properties from Event.

HIDInputReportEvent.data Read only

A DataView containing the data from the input report, excluding the reportId if the HID interface uses report IDs.

HIDInputReportEvent.device Read only

The HIDDevice instance that represents the HID interface that sent the input report.

HIDInputReportEvent.reportId Read only

The one-byte identification prefix for this report, or 0 if the HID interface does not use report IDs.

Example

The following example demonstrates listening for an inputreport event that will allow the application to detect which button is pressed on a Joy-Con Right device. You can see more examples, and live demos in the article Connecting to uncommon HID devices.

js
device.addEventListener("inputreport", (event) => {
  const { data, device, reportId } = event;

  // Handle only the Joy-Con Right device and a specific report ID.
  if (device.productId !== 0x2007 && reportId !== 0x3f) return;

  const value = data.getUint8(0);
  if (value === 0) return;

  const someButtons = { 1: "A", 2: "X", 4: "B", 8: "Y" };
  console.log(`User pressed button ${someButtons[value]}.`);
});

Specifications

Specification
WebHID API
# dom-hiddevice-oninputreport

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
inputreport event
Experimental
Chrome – Full support
Chrome 89 (Release date: 2021-03-02)
footnote Full support
Edge – Full support
Edge 89 (Release date: 2021-03-04)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 75 (Release date: 2021-03-24)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.