I am developing a KMDF virtual mouse driver.
The general idea is a KMDF root enumerated non-filter driver which will be able to send output reports to the mouse and keyboard driver stacks.
My driver is already working and sending requests to other driver stacks, but with no result.
Report types and packet formats are pretty undocumented on Microsoft resources. There are no information about which data and to which device I need to send in order to move the mouse pointer, simulate clicks (with either mouse or keyboard).
There is only general information about HID clients, drivers etc. Their documentation often refers to the Windows Driver Samples git repository, but the repository does not contain any sources close to my task. Few people are in driver development, so there are no tutorials either.
I would appreciate giving me a hint where can I find more about my task.
The answer from Jks Liu already points in the right direction. The best way to emulate a mouse these days is to emulate USB HID hardware.
If your virtual mouse data comes from hardware you have control over, you can as well skip the driver part and make your hardware HID compliant.
If we're talking about a pure software emulation, I think your best bet will be to emulate a USB device that identifies itself as a HID device. There's a great MSDN article on creating your own USB device emulation. The good thing is that they're using HID as an example USB descriptor:
const UCHAR g_UsbDeviceDescriptor[] = {
// Device Descriptor
0x12, // Descriptor Size
0x01, // Device Descriptor Type
0x00, 0x03, // USB 3.0
0x00, // Device class
0x00, // Device sub-class
0x00, // Device protocol
0x09, // Maxpacket size for EP0 : 2^9
0x5E, 0x04, // Vendor ID
0x39, 0x00, // Product ID
0x00, // LSB of firmware version
0x03, // MSB of firmware version
0x01, // Manufacture string index
0x03, // Product string index
0x00, // Serial number string index
0x01 // Number of configurations
};
To know which endpoints and HID data you need to send, you could read the HID specs, but easier would be to take a look into existing microcontroller implementations. A lot of microcontroller brands have examples on how to emulate a USB HID mouse with their USB stack. Some examples:
HID is a standard defined by USB. So Microsoft does not define the format. In fact, HID is so versatile that the format should be defined by yourself in the HID report descriptor.
HID descriptor is defined in Device Class Definition HID and HID Usage Tables.
In page 61 of `Device Class Definition HID' there is an example of mouse which is exact what you want.
Usage Page (Generic Desktop),
Usage (Mouse),
Collection (Application),
Usage (Pointer),
Collection (Physical),
Report Count (3),
Report Size (1),
Usage Page (Buttons),
Usage Minimum (1),
Usage Maximum (3),
Logical Minimum (0),
Logical Maximum (1),
Input (Data, Variable, Absolute),
Report Count (1),
Report Size (5),
Input (Constant),
Report Size (8),
Report Count (2),
Usage Page (Generic Desktop),
Usage (X),
Usage (Y),
Logical Minimum (-127),
Logical Maximum (127),
Input (Data, Variable, Relative),
End Collection,
End Collection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With