Exemplo n.º 1
0
        /// <summary>
        /// Gets all the raw mice and initializes the Mice property.
        /// </summary>
        private void GetRawInputMice()
        {
            _mice = new ArrayList();

            foreach (RAWINPUTDEVICELIST d in Devices)
            {
                //skip everything but mice.
                if (d.dwType != RIM_TYPEMOUSE)
                {
                    continue;
                }

                // Call GetRawInputDeviceInfo once with IntPtr.Zero to allocate enough memory to pcbSize buffer to store RIDI_DEVICENAME
                Int32 pcbSize = 0;
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);

                // Double the buffer size because sometimes the application is Unicode
                IntPtr sb = Marshal.AllocHGlobal((pcbSize * 2) + 2);

                // Now call GetRawInputDeviceInfo again, this time to populate the buffer with RIDI_DEVICENAME
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, sb, ref pcbSize);

                // Store the device name in a stringbuilder
                StringBuilder sbb = new StringBuilder();
                string        aa  = Marshal.PtrToStringAuto(sb);
                char[]        ab  = aa.ToCharArray();
                Marshal.FreeHGlobal(sb);
                sbb.Append(ab);

                // Skip windows terminal (rdp) mouse
                if (sbb.ToString().IndexOf(@"\\?\Root#RDP_MOU#0000#") < 0)
                {
                    // Get size of RID_DEVICE_INFO struct
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, ref pcbSize);

                    // Populate the mouseInfo struct with information about this mouse
                    RID_DEVICE_INFO mouseInfo = new RID_DEVICE_INFO();
                    mouseInfo.cbSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, ref mouseInfo, ref pcbSize);

                    // Create a RawMouse instance for this device and add to the _mice array
                    RawMouse mouse = new RawMouse(d.hDevice, (int)mouseInfo.mouse.dwNumberOfButtons, sbb.ToString());
                    _mice.Add(mouse);
                }
            }
        }
        /// <summary>
        /// Gets all the raw mice and initializes the Mice property.
        /// </summary>
        private void GetRawInputMice()
        {
            _mice = new ArrayList();

            foreach (RAWINPUTDEVICELIST d in Devices)
            {
                //skip everything but mice.
                if (d.dwType != RIM_TYPEMOUSE)
                {
                    continue;
                }

                //Get length of name.
                Int32 pcbSize = 0;
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);

                //Get name
                IntPtr sb = Marshal.AllocHGlobal((pcbSize * 2) + 2);//double size because sometimes the application is unicode
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, sb, ref pcbSize);
                StringBuilder sbb = new StringBuilder();
                string        aa  = Marshal.PtrToStringAuto(sb);
                char[]        ab  = aa.ToCharArray();
                Marshal.FreeHGlobal(sb);

                sbb.Append(ab);
                //skip windows terminal (rdp) mouse
                if (sbb.ToString().IndexOf(@"\\?\Root#RDP_MOU#0000#") < 0)
                {
                    //Get size of RID_DEVICE_INFO struct
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, ref pcbSize);

                    //Get the struct.
                    RID_DEVICE_INFO mouseInfo = new RID_DEVICE_INFO();
                    //Set cbSize as per docs on GetRawInputDeviceInfo
                    mouseInfo.cbSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, ref mouseInfo, ref pcbSize);

                    //Create our state container
                    RawMouse mouse = new RawMouse(d.hDevice, (int)mouseInfo.mouse.dwNumberOfButtons, sbb.ToString());
                    _mice.Add(mouse);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all the raw mice and initializes the Mice property.
        /// </summary>
        private void GetRawInputMice()
        {
            _mice = new ArrayList();

            foreach (RAWINPUTDEVICELIST d in Devices)
            {
                //skip everything but mice.
                if (d.dwType != RIM_TYPEMOUSE)
                {
                    continue;
                }

                //Get length of name.
                Int32 pcbSize = 0;
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);

                //Get name
                StringBuilder sb = new StringBuilder();
                GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICENAME, sb, ref pcbSize);

                //skip windows terminal (rdp?) mouse
                if (sb.ToString().IndexOf(@"\??\Root#RDP_MOU#0000#") < 0)
                {
                    //Get size of RID_DEVICE_INFO struct
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, ref pcbSize);

                    //Get the struct.
                    RID_DEVICE_INFO mouseInfo = new RID_DEVICE_INFO();
                    //Set cbSize as per docs on GetRawInputDeviceInfo
                    mouseInfo.cbSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
                    GetRawInputDeviceInfo(d.hDevice, RIDI_DEVICEINFO, ref mouseInfo, ref pcbSize);

                    //Create our state container
                    RawMouse mouse = new RawMouse(d.hDevice, (int)mouseInfo.mouse.dwNumberOfButtons, sb.ToString());
                    _mice.Add(mouse);
                }
            }
        }