Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically differentiating between physical or virtual keyboards

I am writing a Windows C++ library and I need to find a way to detect whether the keyboard devices connected are physical or just virtual.

I have tried using the KeyboardPresent member of the Windows::Devices::Input::KeyboardCapabilities class, but that returns true even when there are no physical keyboards present.

I have also tried using the Windows::Devices::Enumeration::DeviceInformation class, but the information returned from it, as thorough as it gets, doesn't seem to contain information about the nature of the device. Perhaps it does and I missed it?

Both of these approaches were tested on a Surface 4 Pro.

like image 957
TedNC Avatar asked Oct 21 '25 11:10

TedNC


1 Answers

This information isn't provided by any Windows API, because Windows itself doesn't know which devices are virtual or physical.

Devices are controlled by drivers, which are software that runs with elevated rights on a very low level in the operating system. Specifically the driver hides away the specifics of the hardware from Windows, including if it's physical or virtual.

The only way(s) I can think of:

  • Compile a list of known virtual keyboard names/hardware ids and identify keyboards with that.

  • Compile a list of known virtual device drivers and identify the driver used for a particular keyboard.

  • Write a driver yourself that hooks into the code of other drivers and checks their I/O behavior with hardware. If it sends input to the OS that doesn't correspond to real hardware input, you might have a virtual device driver. This approach is super risky of course.

  • A combination of the above.

like image 156
Max Vollmer Avatar answered Oct 22 '25 23:10

Max Vollmer