How to inject virtual keyboard or mouse event via vhf(virtual hid framework)?

jianbin zhang 20 Reputation points
2025-05-20T02:22:44.0866667+00:00

Hi MSFT HID team,

We use the VHF to develop the virutal hid keyboard event / mouse event, the total call flow is
Own UMD -> hidclass -> vhf -> hvfkmlib -> Own hid source KMD -> hvfkmlib, but actually there are no response (I sent "a" keyboard event but there is no "a" char prompt / also I set the mouse moving and right click event but also no respond.)

Could u pls help to check if there any wrong ? why there is no related event prompted?

Here list some api call flow we used in the UMD & KMD,

  • For Keyboard Enter event

UMD:

First: struct a input report:
`INPUT inp = { 0 };`
     inp.type = INPUT_KEYBOARD;
     inp.ki.wVk = 0x0D; (Enter key)
     inp.ReportId = 1;
     inp->Report.KeyReport.Key1 = 0x28;
 Second: Use WriteFile to send to KMD
 `WriteFile(	`
        g_hFile,
		Rep,
		sizeof(*Rep),
		&BytesWritten,
		NULL
	);

KMD: receive the report and use vhfreadreportsubbmit to the vhfkmlib.

  • For Mouse moving event

UMD:

Struct a mouse moving and right repot:
    inp.type = INPUT_MOUSE;
    inp.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN(0x0001);
    inp.mi.dx = 6400;
    inp.mi.dy = 1600;
    MouseState.Report.MouseReport.Buttons |= 0x01;
    MouseState.Report.MouseReport.AbsoluteX = Input->mi.dx >> 1;
    MouseState.Report.MouseReport.AbsoluteY = Input->mi.dy >> 1;
BOOL SendHidReport(HIDINJECTOR_INPUT_REPORT* Rep)
{
if (g_hFile != NULL)
{
	DWORD BytesWritten = 0;
	return WriteFile(
		g_hFile,
		Rep,
		sizeof(*Rep),
		&BytesWritten,
		NULL
	);
}
return FALSE;
}

KMD: receive the report and use vhfreadreportsubbmit to the vhfkmlib.

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
11,864 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.