HidDevice.InputReportReceived 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當 呼叫 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)
事件類型
範例
在這裡,我們會擷取輸入報表 (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 讀取要求傳送至堆疊中的較低驅動程式。
HID 迷你驅動程式會將 IOCTL 轉譯為通訊協定特定要求。 對於 USB 裝置,迷你驅動程式會將它轉譯為插斷 IN 要求。 而且,對於透過 Microsoft HID-I2C 迷你埠驅動程式執行的 I2C 裝置,迷你驅動程式會等候裝置判斷提示中斷。