private int InitKeyboard() { bool flag = true; int num1 = 0; Guid guid = new Guid("4d1e55b2-f16f-11cf-88cb-001111000030"); IntPtr classDevs = Native.SetupDiGetClassDevs(ref guid, 0, IntPtr.Zero, 18); classDevs.ToInt32(); int memberIndex = 0; while (flag) { Native.SP_DEVICE_INTERFACE_DATA deviceInterfaceData = new Native.SP_DEVICE_INTERFACE_DATA(); flag = Native.SetupDiEnumDeviceInterfaces(classDevs, (Native.SP_DEVINFO_DATA)null, ref guid, memberIndex, deviceInterfaceData); if (flag) { Native.SP_DEVINFO_DATA deviceInfoData = new Native.SP_DEVINFO_DATA(); int requiredSize = 0; Native.SetupDiGetDeviceInterfaceDetail(classDevs, deviceInterfaceData, IntPtr.Zero, 0, ref requiredSize, deviceInfoData); IntPtr num2 = Marshal.AllocHGlobal(requiredSize); Marshal.StructureToPtr((object)new Native.SP_DEVICE_INTERFACE_DETAIL_DATA() { cbSize = (IntPtr.Size != 8 ? 4 + Marshal.SystemDefaultCharSize : 8) }, num2, false); Native.SetupDiGetDeviceInterfaceDetail(classDevs, deviceInterfaceData, num2, requiredSize, ref requiredSize, deviceInfoData); string stringAuto = Marshal.PtrToStringAuto((IntPtr)((int)num2 + Marshal.SizeOf(typeof(int)))); Marshal.FreeHGlobal(num2); if (stringAuto.IndexOf("04d9") > 0 && stringAuto.IndexOf("8008") > 0 || stringAuto.IndexOf("1044") > 0 && stringAuto.IndexOf("7a38") > 0 || stringAuto.IndexOf("1044") > 0 && stringAuto.IndexOf("7a39") > 0) { SECURITY_ATTRIBUTES securityAttributes = new SECURITY_ATTRIBUTES(); securityAttributes.nLength = Marshal.SizeOf((object)securityAttributes); securityAttributes.lpSecurityDescriptor = IntPtr.Zero; securityAttributes.bInheritHandle = 0; IntPtr file = Win32.CreateFile(stringAuto, 3221225472U, 3, IntPtr.Zero, 3, 0, 0); if (file.ToInt32() != -1) { IntPtr PreparsedData = new IntPtr(); Win32.HidD_GetPreparsedData(file, ref PreparsedData); HIDP_CAPS Capabilities = new HIDP_CAPS(); Win32.HidP_GetCaps(PreparsedData, ref Capabilities); if ((int)Capabilities.FeatureReportByteLength > 0) { _deviceHandle_2016 = file; break; } } } else if ((stringAuto.IndexOf("1044") <= 0 || stringAuto.IndexOf("7a03") <= 0) && (stringAuto.IndexOf("1044") <= 0 || stringAuto.IndexOf("7a04") <= 0) && stringAuto.IndexOf("1044") > 0) { stringAuto.IndexOf("7a06"); } ++memberIndex; } } return(num1); }
public static string GetName(IntPtr hDevInfo) { try { Native.SP_DEVINFO_DATA DeviceInfoData; DeviceInfoData = new Native.SP_DEVINFO_DATA(); DeviceInfoData.cbSize = 28; //is devices exist for class DeviceInfoData.devInst = 0; DeviceInfoData.classGuid = System.Guid.Empty; DeviceInfoData.reserved = 0; UInt32 i; StringBuilder DeviceName = new StringBuilder(""); DeviceName.Capacity = Native.MAX_DEV_LEN; for (i = 0; Native.SetupDiEnumDeviceInfo(hDevInfo, i, DeviceInfoData); i++) { //Debug.WriteLine(hDevInfo + " - " + i + "- " + DeviceInfoData.classGuid); //Declare vars int skip = 0; while (!Native.SetupDiGetDeviceRegistryProperty(hDevInfo, DeviceInfoData, Native.SPDRP_DEVICEDESC, 0, DeviceName, Native.MAX_DEV_LEN, IntPtr.Zero)) { // Debug.WriteLine("Skip"); skip++; if (skip > 1024) { Debug.WriteLine("skipping"); break; } } if (skip < 1024) { //Debug.WriteLine(skip+ " Got Name " +DeviceName.ToString()); return(DeviceName.ToString()); } } } catch { } return(null); }