Adding status bar to show the device that just sent an event.
2 using System.Runtime.InteropServices;
3 using Microsoft.Win32.SafeHandles;
9 static partial class Function
11 [DllImport("hid.dll", CharSet = CharSet.Unicode)]
12 public static extern HidStatus HidP_GetUsagesEx(HIDP_REPORT_TYPE ReportType, ushort LinkCollection, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] USAGE_AND_PAGE[] ButtonList, ref uint UsageLength, IntPtr PreparsedData, [MarshalAs(UnmanagedType.LPArray)] byte[] Report, uint ReportLength);
14 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
15 public static extern Boolean HidD_GetManufacturerString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
17 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
18 public static extern Boolean HidD_GetProductString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
20 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
21 public static extern Boolean HidD_GetAttributes(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
23 /// Return Type: NTSTATUS->LONG->int
24 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
25 ///Capabilities: PHIDP_CAPS->_HIDP_CAPS*
26 [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)]
27 public static extern HidStatus HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities);
29 /// Return Type: NTSTATUS->LONG->int
30 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
31 ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS*
32 ///ButtonCapsLength: PUSHORT->USHORT*
33 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
34 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
35 public static extern HidStatus HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] HIDP_BUTTON_CAPS[] ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData);
37 /// Return Type: NTSTATUS->LONG->int
38 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
39 ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS*
40 ///ValueCapsLength: PUSHORT->USHORT*
41 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
42 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
43 public static extern HidStatus HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] HIDP_VALUE_CAPS[] ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData);
48 static partial class Macro
55 static partial class Const
62 public enum HIDP_REPORT_TYPE : ushort
70 public enum HidStatus : uint
72 HIDP_STATUS_SUCCESS = 0x110000,
73 HIDP_STATUS_NULL = 0x80110001,
74 HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
75 HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
76 HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
77 HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
78 HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
79 HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
80 HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
81 HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
82 HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
83 HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
84 HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
85 HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
86 HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
87 HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
88 HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
89 HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
90 HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
91 HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
95 [StructLayout(LayoutKind.Sequential)]
96 public struct USAGE_AND_PAGE
99 public ushort UsagePage;
102 [StructLayout(LayoutKind.Sequential)]
103 public struct HIDD_ATTRIBUTES
106 public ushort VendorID;
107 public ushort ProductID;
108 public ushort VersionNumber;
112 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
113 public struct HIDP_CAPS
115 /// USAGE->USHORT->unsigned short
118 /// USAGE->USHORT->unsigned short
119 public ushort UsagePage;
121 /// USHORT->unsigned short
122 public ushort InputReportByteLength;
124 /// USHORT->unsigned short
125 public ushort OutputReportByteLength;
127 /// USHORT->unsigned short
128 public ushort FeatureReportByteLength;
131 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 17, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
132 public ushort[] Reserved;
134 /// USHORT->unsigned short
135 public ushort NumberLinkCollectionNodes;
137 /// USHORT->unsigned short
138 public ushort NumberInputButtonCaps;
140 /// USHORT->unsigned short
141 public ushort NumberInputValueCaps;
143 /// USHORT->unsigned short
144 public ushort NumberInputDataIndices;
146 /// USHORT->unsigned short
147 public ushort NumberOutputButtonCaps;
149 /// USHORT->unsigned short
150 public ushort NumberOutputValueCaps;
152 /// USHORT->unsigned short
153 public ushort NumberOutputDataIndices;
155 /// USHORT->unsigned short
156 public ushort NumberFeatureButtonCaps;
158 /// USHORT->unsigned short
159 public ushort NumberFeatureValueCaps;
161 /// USHORT->unsigned short
162 public ushort NumberFeatureDataIndices;
166 /// Type created in place of an anonymous struct
168 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
169 public struct HIDP_BUTTON_CAPS_RANGE
172 /// USAGE->USHORT->unsigned short
173 public ushort UsageMin;
175 /// USAGE->USHORT->unsigned short
176 public ushort UsageMax;
178 /// USHORT->unsigned short
179 public ushort StringMin;
181 /// USHORT->unsigned short
182 public ushort StringMax;
184 /// USHORT->unsigned short
185 public ushort DesignatorMin;
187 /// USHORT->unsigned short
188 public ushort DesignatorMax;
190 /// USHORT->unsigned short
191 public ushort DataIndexMin;
193 /// USHORT->unsigned short
194 public ushort DataIndexMax;
198 /// Type created in place of an anonymous struct
200 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
201 public struct HIDP_BUTTON_CAPS_NOT_RANGE
204 /// USAGE->USHORT->unsigned short
207 /// USAGE->USHORT->unsigned short
208 public ushort Reserved1;
210 /// USHORT->unsigned short
211 public ushort StringIndex;
213 /// USHORT->unsigned short
214 public ushort Reserved2;
216 /// USHORT->unsigned short
217 public ushort DesignatorIndex;
219 /// USHORT->unsigned short
220 public ushort Reserved3;
222 /// USHORT->unsigned short
223 public ushort DataIndex;
225 /// USHORT->unsigned short
226 public ushort Reserved4;
232 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
233 public struct HIDP_BUTTON_CAPS
235 /// USAGE->USHORT->unsigned short
237 public ushort UsagePage;
239 /// UCHAR->unsigned char
241 public byte ReportID;
243 /// BOOLEAN->BYTE->unsigned char
245 [MarshalAsAttribute(UnmanagedType.U1)]
248 /// USHORT->unsigned short
250 public ushort BitField;
252 /// USHORT->unsigned short
254 public ushort LinkCollection;
256 /// USAGE->USHORT->unsigned short
258 public ushort LinkUsage;
260 /// USAGE->USHORT->unsigned short
262 public ushort LinkUsagePage;
264 /// BOOLEAN->BYTE->unsigned char
266 [MarshalAsAttribute(UnmanagedType.U1)]
269 /// BOOLEAN->BYTE->unsigned char
271 [MarshalAsAttribute(UnmanagedType.U1)]
272 public bool IsStringRange;
274 /// BOOLEAN->BYTE->unsigned char
276 [MarshalAsAttribute(UnmanagedType.U1)]
277 public bool IsDesignatorRange;
279 /// BOOLEAN->BYTE->unsigned char
281 [MarshalAsAttribute(UnmanagedType.U1)]
282 public bool IsAbsolute;
286 [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.U4)]
287 public uint[] Reserved;
289 /// Union Range/NotRange
291 HIDP_BUTTON_CAPS_RANGE Range;
294 HIDP_BUTTON_CAPS_NOT_RANGE NotRange;
298 /// Type created in place of an anonymous struct
300 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
301 public struct HIDP_VALUE_CAPS_RANGE
304 /// USAGE->USHORT->unsigned short
305 public ushort UsageMin;
307 /// USAGE->USHORT->unsigned short
308 public ushort UsageMax;
310 /// USHORT->unsigned short
311 public ushort StringMin;
313 /// USHORT->unsigned short
314 public ushort StringMax;
316 /// USHORT->unsigned short
317 public ushort DesignatorMin;
319 /// USHORT->unsigned short
320 public ushort DesignatorMax;
322 /// USHORT->unsigned short
323 public ushort DataIndexMin;
325 /// USHORT->unsigned short
326 public ushort DataIndexMax;
330 /// Type created in place of an anonymous struct
332 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
333 public struct HIDP_VALUE_CAPS_NOT_RANGE
336 /// USAGE->USHORT->unsigned short
339 /// USAGE->USHORT->unsigned short
340 public ushort Reserved1;
342 /// USHORT->unsigned short
343 public ushort StringIndex;
345 /// USHORT->unsigned short
346 public ushort Reserved2;
348 /// USHORT->unsigned short
349 public ushort DesignatorIndex;
351 /// USHORT->unsigned short
352 public ushort Reserved3;
354 /// USHORT->unsigned short
355 public ushort DataIndex;
357 /// USHORT->unsigned short
358 public ushort Reserved4;
365 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
366 public struct HIDP_VALUE_CAPS
369 /// USAGE->USHORT->unsigned short
371 public ushort UsagePage;
373 /// UCHAR->unsigned char
375 public byte ReportID;
377 /// BOOLEAN->BYTE->unsigned char
379 [MarshalAsAttribute(UnmanagedType.U1)]
382 /// USHORT->unsigned short
384 public ushort BitField;
386 /// USHORT->unsigned short
388 public ushort LinkCollection;
390 /// USAGE->USHORT->unsigned short
392 public ushort LinkUsage;
394 /// USAGE->USHORT->unsigned short
396 public ushort LinkUsagePage;
398 /// BOOLEAN->BYTE->unsigned char
400 [MarshalAsAttribute(UnmanagedType.U1)]
403 /// BOOLEAN->BYTE->unsigned char
405 [MarshalAsAttribute(UnmanagedType.U1)]
406 public bool IsStringRange;
408 /// BOOLEAN->BYTE->unsigned char
410 [MarshalAsAttribute(UnmanagedType.U1)]
411 public bool IsDesignatorRange;
413 /// BOOLEAN->BYTE->unsigned char
415 [MarshalAsAttribute(UnmanagedType.U1)]
416 public bool IsAbsolute;
418 /// BOOLEAN->BYTE->unsigned char
420 [MarshalAsAttribute(UnmanagedType.U1)]
423 /// UCHAR->unsigned char
425 public byte Reserved;
427 /// USHORT->unsigned short
429 public ushort BitSize;
431 /// USHORT->unsigned short
433 public ushort ReportCount;
436 /// We had to use 5 ushorts instead of an array to avoid alignment exception issues.
438 public ushort Reserved21;
440 public ushort Reserved22;
442 public ushort Reserved23;
444 public ushort Reserved24;
446 public ushort Reserved25;
448 /// ULONG->unsigned int
450 public uint UnitsExp;
452 /// ULONG->unsigned int
458 public int LogicalMin;
462 public int LogicalMax;
466 public int PhysicalMin;
470 public int PhysicalMax;
472 /// Union Range/NotRange
474 public HIDP_VALUE_CAPS_RANGE Range;
477 public HIDP_VALUE_CAPS_NOT_RANGE NotRange;