/// <summary> /// Creates new HID data reader. /// </summary> /// <param name="window">Window instance, which will reveice the WM_INPUT messages</param> public HidDataReader(Window window) { if (window == null) { throw new ArgumentNullException("window"); } this.window = window; this.window.Closed += this.OnWindowClosed; var handle = new WindowInteropHelper(this.window).Handle; var source = HwndSource.FromHwnd(handle); source.AddHook(this.WndProc); var devices = RawInputHelper.GetDevices(); int i = 0; RAWINPUTDEVICE[] rids = new RAWINPUTDEVICE[devices.Count]; // Setting handle to each rid device to receive the WM_INPUT message foreach (var device in devices) { rids[i].usUsagePage = device.UsagePage; rids[i].usUsage = device.UsageCollection; rids[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rids[i].hwndTarget = handle; i++; } this.handler = new HidHandler(rids); this.handler.OnHidEvent += this.OnHidEvent; }
public static List <Device> GetDevices() { var devices = RawInputHelper.GetDevices(); return(devices); }
public HidDataReader(Window window) : this(window, RawInputHelper.GetDevices()) { }