Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HIDDevice
  4. inputreport

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 insecure contexts (HTTPS), in some or allsupporting browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

Note: This feature is available inWeb Workers, except forShared Web Workers.

Theinputreport event of theHIDDevice interface fires when a new report is received from the HID device.

Syntax

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

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

Event type

AnHIDInputReportEvent. Inherits fromEvent.

Event HIDInputReportEvent

Event properties

This interface also inherits properties fromEvent.

HIDInputReportEvent.dataRead only

ADataView containing the data from the input report, excluding thereportId if the HID interface uses report IDs.

HIDInputReportEvent.deviceRead only

TheHIDDevice instance that represents the HID interface that sent the input report.

HIDInputReportEvent.reportIdRead 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 aninputreport 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 articleConnecting 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

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp