HidDevice.InputReportReceived 事件

定义

建立一个事件侦听器,用于处理在调用 GetInputReportAsync () GetInputReportAsync (System.UInt16 reportId) 时设备发出的输入报告。

// Register
event_token InputReportReceived(TypedEventHandler<HidDevice, HidInputReportReceivedEventArgs const&> const& handler) const;

// Revoke with event_token
void InputReportReceived(event_token const* cookie) const;

// Revoke with event_revoker
HidDevice::InputReportReceived_revoker InputReportReceived(auto_revoke_t, TypedEventHandler<HidDevice, HidInputReportReceivedEventArgs const&> const& handler) const;
public event TypedEventHandler<HidDevice,HidInputReportReceivedEventArgs> InputReportReceived;
function onInputReportReceived(eventArgs) { /* Your code */ }
hidDevice.addEventListener("inputreportreceived", onInputReportReceived);
hidDevice.removeEventListener("inputreportreceived", onInputReportReceived);
- or -
hidDevice.oninputreportreceived = onInputReportReceived;
Public Custom Event InputReportReceived As TypedEventHandler(Of HidDevice, HidInputReportReceivedEventArgs) 

事件类型

示例

在这里,我们将检索 input 报表 (inputReport) ,并在异步调用完成时触发的 InputReportReceived 事件的处理程序中获取报表的内容。

HidInputReport inputReport = await device.GetInputReportAsync();
.
.
.
private void InputReportReceived(
    HidDevice sender, 
    HidInputReportReceivedEventArgs args)
    {
        HidInputReport inputReport = args.Report;
        IBuffer buffer = inputReport.Data;
        DataReader dr = DataReader.FromBuffer(buffer);
        byte[] bytes = new byte[inputReport.Data.Length];
        dr.ReadBytes(bytes);

        String inputReportContent = 
           System.Text.Encoding.ASCII.GetString(bytes);
    }

注解

此方法等待设备在有要发送的数据时中断主机。 在内部,HID WinRT API 将 IOCTL 读取请求发送到堆栈中的较低驱动程序。

IOCTL 由 HID 微型驱动程序转换为特定于协议的请求。 对于 USB 设备,微型驱动程序将此转换为 INTERRUPT IN 请求。 并且,对于通过 Microsoft HID-I2C 微型端口驱动程序运行的 I2C 设备,微型驱动程序将等待设备断言中断。

适用于

另请参阅