/// <summary> /// Registers the window to receive high definition mouse input through WM_INPUT /// </summary> /// <param name="windowHandle">Handle of the window that will receive WM_INPUT</param> private void registerForRawInput(IntPtr windowHandle) { UnsafeNativeMethods.RAWINPUTDEVICE rawInputDevice; rawInputDevice.UsagePage = UnsafeNativeMethods.HID_USAGE_PAGE_GENERIC; rawInputDevice.Usage = UnsafeNativeMethods.HID_USAGE_GENERIC_MOUSE; rawInputDevice.Flags = 0; rawInputDevice.WindowHandle = windowHandle; bool result = UnsafeNativeMethods.RegisterRawInputDevices( ref rawInputDevice, 1, Marshal.SizeOf(rawInputDevice) ); if (!result) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }