public RawInputUtils(IntPtr hwnd) { NativeImport.NativeStructs.RAWINPUTDEVICE[] rid = new NativeImport.NativeStructs.RAWINPUTDEVICE[1]; rid[0].usUsagePage = 0x01; rid[0].usUsage = 0x02; rid[0].dwFlags = RIDEV_INPUTSINK; rid[0].hwndTarget = hwnd; if (!NativeImport.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0]))) { throw new ApplicationException("Failed to register raw input device(s)."); } }