示例#1
0
 public void EnumerateMice()
 {
     lock (_lock)
     {
         _mouseList.Clear();
         uint devices = 0u;
         int  size    = Marshal.SizeOf(typeof(RawInputDeviceList));
         if (Win32Methods.GetRawInputDeviceList(IntPtr.Zero, ref devices, (uint)size) != 0u)
         {
             throw new Win32Exception(Marshal.GetLastWin32Error());
         }
         IntPtr pRawInputDeviceList = Marshal.AllocHGlobal((int)(size * devices));
         try
         {
             Win32Methods.GetRawInputDeviceList(pRawInputDeviceList, ref devices, (uint)size);
             int index = 0;
             while (index < devices)
             {
                 RawMouseDevice device = GetMouse(pRawInputDeviceList, size, index);
                 if (device != null && !_mouseList.ContainsKey(device.Handle))
                 {
                     _mouseList.Add(device.Handle, device);
                 }
                 index++;
             }
         }
         finally
         {
             Marshal.FreeHGlobal(pRawInputDeviceList);
         }
         NumberOfMice = _mouseList.Count;
     }
 }
示例#2
0
 internal RawInputMouseEventArgs(RawMouseDevice device, ushort flags, ushort buttonFlags, short buttonData, int lastX, int lastY)
 {
     Device      = device;
     Flags       = flags;
     ButtonFlags = buttonFlags;
     ButtonData  = buttonData;
     LastX       = lastX;
     LastY       = lastY;
 }