コード例 #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");
        }
コード例 #2
0
 public static extern bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, uint uiNumDevices, uint cbSize);
コード例 #3
0
 public static bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, int iNumDevices, int cbSize)
 {
     return NativeMethods.RegisterRawInputDevices(pRawInputDevice, (uint)iNumDevices, (uint)cbSize);
 }
コード例 #4
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]));
            }
        }