我正在开发一个需要检测是否存在触摸屏的应用程序。我正在使用以下代码,它在大多数情况下都有效:
TouchCapabilities^ tc = ref new TouchCapabilities();
return tc->TouchPresent;
问题是我有一台笔记本电脑,触摸板返回 true,没有触摸屏。我试图用以下代码检测是否存在触摸屏,但它永远不会在触摸屏部分内中断。我承认我对自己对 HID 的理解不是很有信心。
Windows::Foundation::Collections::IVectorView<PointerDevice^>^ devices = Windows::Devices::Input::PointerDevice::GetPointerDevices();
for (int i = 0; i < devices->Size; ++i)
{
PointerDevice^ pd = devices->GetAt(i);
PointerDeviceType pdt = pd->PointerDeviceType;
unsigned int contacts = pd->MaxContacts;
bool integrated = pd->IsIntegrated;
for (int j = 0; j < pd->SupportedUsages->Size; ++j)
{
PointerDeviceUsage pdu = pd->SupportedUsages->GetAt(j);
unsigned int usagePage = pdu.UsagePage;
if (usagePage == 0x0D) // 0x0D is the Digitizer HID Usage Page
{
unsigned int usage = pdu.Usage;
if (pdu.Usage == 0x04) // 0x04 is the Touch Screen HID Usage ID
{
// Should be touch screen but never goes in here
}
}
}
}
有没有办法专门检测触摸屏?如果是这样,是否可以看到一些示例代码?