Esempio n. 1
0
        public RawInput(IntPtr handle)
        {
            this.handle  = handle;
            mice         = new List <DeviceInfo>();
            keyboards    = new List <DeviceInfo>();
            otherDevices = new List <DeviceInfo>();

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage = Win32RawInput.HID_HWIND.HidMouse.UsagePage;
            rid[0].usUsage     = Win32RawInput.HID_HWIND.HidMouse.UsageId;
            rid[0].dwFlags     = (int)RIDEV.INPUTSINK;
            rid[0].hwndTarget  = handle;

            if (!Win32RawInput.RegisterRawInputDevices(rid, rid.Length, Marshal.SizeOf(rid[0])))
            {
                throw new Win32Exception("Failed to register raw input device(s).");
            }

            int loadedDevices = LoadDevices();

            if (mice.Count <= 0)
            {
                throw new Win32Exception("Unable to detect an attached mouse");
            }
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                if (disposing)
                {
                    // Dispose managed resources
                    // N/A
                }

                // Dispose unmanaged resources.
                RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
                rid[0].usUsagePage = Win32RawInput.HID_HWIND.HidMouse.UsagePage;
                rid[0].usUsage     = Win32RawInput.HID_HWIND.HidMouse.UsageId;
                rid[0].dwFlags     = (int)RIDEV.REMOVE;
                rid[0].hwndTarget  = this.handle;
                Win32RawInput.RegisterRawInputDevices(rid, rid.Length, Marshal.SizeOf(rid[0]));
            }
        }