Ejemplo n.º 1
0
        private static bool IsAppleWirelessKeyboard(int vid, int pid)
        {
            if (vid == VIDApple)
            {
                Guid HIDGUID;
                HIDImports.HidD_GetHidGuid(out HIDGUID);

                IntPtr DeviceInfo = HIDImports.SetupDiGetClassDevs(ref HIDGUID, null, IntPtr.Zero, 16);

                uint MemberIndex = 0;

                HIDImports.SP_DEVINFO_DATA DID = new HIDImports.SP_DEVINFO_DATA()
                {
                    cbSize = (uint)Marshal.SizeOf(typeof(HIDImports.SP_DEVINFO_DATA))
                };

                while (HIDImports.SetupDiEnumDeviceInfo(DeviceInfo, MemberIndex++, ref DID))
                {
                    uint   RequiredSize     = 0;
                    uint   PropertyDataType = 0;
                    IntPtr buffer           = Marshal.AllocHGlobal(512);
                    string CLASS            = "";


                    if (HIDImports.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DID, (uint)HIDImports.SPDRP.SPDRP_CLASS, out PropertyDataType, buffer, 512, out RequiredSize))
                    {
                        CLASS = Marshal.PtrToStringAuto(buffer);
                    }

                    if (CLASS.Equals("Keyboard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }

                HIDImports.SetupDiDestroyDeviceInfoList(DeviceInfo);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static bool IsAppleWirelessKeyboard(int vid, int pid)
        {
            if (vid == VIDApple)
            {
                Guid HIDGUID;
                HIDImports.HidD_GetHidGuid(out HIDGUID);

                IntPtr DeviceInfo = HIDImports.SetupDiGetClassDevs(ref HIDGUID, null, IntPtr.Zero, 16);

                uint MemberIndex = 0;

                HIDImports.SP_DEVINFO_DATA DID = new HIDImports.SP_DEVINFO_DATA() { cbSize = (uint)Marshal.SizeOf(typeof(HIDImports.SP_DEVINFO_DATA)) };

                while (HIDImports.SetupDiEnumDeviceInfo(DeviceInfo, MemberIndex++, ref DID))
                {
                    uint RequiredSize = 0;
                    uint PropertyDataType = 0;
                    IntPtr buffer = Marshal.AllocHGlobal(512);
                    string CLASS = "";

                    if (HIDImports.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DID, (uint)HIDImports.SPDRP.SPDRP_CLASS, out PropertyDataType, buffer, 512, out RequiredSize))
                        CLASS = Marshal.PtrToStringAuto(buffer);

                    if (CLASS.Equals("Keyboard", StringComparison.InvariantCultureIgnoreCase))
                        return true;
                }

                HIDImports.SetupDiDestroyDeviceInfoList(DeviceInfo);

                return true;
            }
            else return false;
        }