The inputreport
event of the HIDDevice
interface fires when a new report is received from the HID device.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener("inputreport", (event) => {});
oninputreport = (event) => {};
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.
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.
device.addEventListener("inputreport", (event) => {
const { data, device, reportId } = event;
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]}.`);
});