public void EnumerateHid() { lock (_lock) { _hidList.Clear(); uint devices = 0u; int size = Marshal.SizeOf(typeof(RawInputDeviceList)); if (Win32Methods.GetRawInputDeviceList(IntPtr.Zero, ref devices, (uint)size) != 0u) { throw new Win32Exception(Marshal.GetLastWin32Error()); } IntPtr pRawInputDeviceList = Marshal.AllocHGlobal((int)(size * devices)); try { Win32Methods.GetRawInputDeviceList(pRawInputDeviceList, ref devices, (uint)size); int index = 0; while (index < devices) { RawHidDevice device = GetHid(pRawInputDeviceList, size, index); if (device != null && !_hidList.ContainsKey(device.Handle)) { Debug.WriteLine("Added Hid; Handle: {0}, Name: {1}, Type: {2}, Description: {3}", (uint)device.Handle, device.Name, device.Type, device.Description); _hidList.Add(device.Handle, device); } index++; } } finally { Marshal.FreeHGlobal(pRawInputDeviceList); } NumberOfHid = _hidList.Count; } }
internal RawInputHidEventArgs(RawHidDevice device, uint sizeHid, uint count, byte[] rawData) { Device = device; SizeHid = sizeHid; Count = count; RawData = new byte[sizeHid * count]; for (int i = 0; i < sizeHid * count; i++) { RawData[i] = rawData[i]; } }