예제 #1
0
 internal static extern bool GetPointerDeviceRects(IntPtr hDevice, ref Rect pointerDeviceRect, ref Rect displayRect);
예제 #2
0
        public static void DeviceAudit()
        {
            var file = new FileStream("DeviceAudit.txt", FileMode.Create, FileAccess.Write);
            var sw = new StreamWriter(file);

            var keyboardNumber = 0;
            uint deviceCount = 0;
            var dwSize = (Marshal.SizeOf(typeof(Rawinputdevicelist)));

            if (GetRawInputDeviceList(IntPtr.Zero, ref deviceCount, (uint)dwSize) == 0)
            {
                var pRawInputDeviceList = Marshal.AllocHGlobal((int)(dwSize * deviceCount));
                GetRawInputDeviceList(pRawInputDeviceList, ref deviceCount, (uint)dwSize);

                for (var i = 0; i < deviceCount; i++)
                {
                    uint pcbSize = 0;

                    // On Window 8 64bit when compiling against .Net > 3.5 using .ToInt32 you will generate an arithmetic overflow. Leave as it is for 32bit/64bit applications
                    var rid = (Rawinputdevicelist)Marshal.PtrToStructure(new IntPtr((pRawInputDeviceList.ToInt64() + (dwSize * i))), typeof(Rawinputdevicelist));

                    GetRawInputDeviceInfo(rid.hDevice, RawInputDeviceInfo.RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);

                    if (pcbSize <= 0)
                    {
                        sw.WriteLine("pcbSize: " + pcbSize);
                        sw.WriteLine(Marshal.GetLastWin32Error());
                        return;
                    }

                    var size = (uint)Marshal.SizeOf(typeof(DeviceInfo));
                    var di = new DeviceInfo {Size = Marshal.SizeOf(typeof (DeviceInfo))};

                    if (GetRawInputDeviceInfo(rid.hDevice, (uint) RawInputDeviceInfo.RIDI_DEVICEINFO, ref di, ref size) <= 0)
                    {
                        sw.WriteLine(Marshal.GetLastWin32Error());
                        return;
                    }

                    var pData = Marshal.AllocHGlobal((int)pcbSize);
                    GetRawInputDeviceInfo(rid.hDevice, RawInputDeviceInfo.RIDI_DEVICENAME, pData, ref pcbSize);
                    var deviceName = Marshal.PtrToStringAnsi(pData);

                    if (rid.dwType == DeviceType.RimTypeHid)
                    {
                        if ((ushort)HidUsagePage.Digitizer == di.HIDInfo.UsagePage && ((ushort)HidUsage.Joystick)== di.HIDInfo.Usage)
                        {
                            TouchDevice = new TouchDevice();
                            FoundTouchScreen = true;

                            Rect pointerRect = new Rect();
                            Rect displayRect = new Rect();

                            // Find the device rects
                            GetPointerDeviceRects(rid.hDevice, ref pointerRect, ref displayRect);

                            TouchDevice.DeviceInfo = di.HIDInfo;
                            TouchDevice.ProductId = di.HIDInfo.ProductID;
                            TouchDevice.VendorId = di.HIDInfo.VendorID;
                            TouchDevice.Width = pointerRect.Width;

                            // Console.WriteLine($"{VendorID} : {ProductID}");
                        }
                    }
                                       

                    Marshal.FreeHGlobal(pData);
                }

                Marshal.FreeHGlobal(pRawInputDeviceList);

                sw.Flush();
                sw.Close();
                file.Close();

                return;
            }

            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
예제 #3
0
 public bool Equals(Rect r)
 {
     return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom;
 }