(如何)我可以在 Windows 上模拟触摸事件吗?

(How) Can I emulate touch events on Windows?

我用 C++ 编写的用于测试目的的实用程序目前使用 SendInput function to emulate user input, i.e. mouse and keyboard events. I'd now like to extend my program such that it's able to emulate touch events, such that I can verify that the tested program handles e.g. WM_TOUCH messages correctly (though that message is deprecated,我仍然想验证它是否已正确处理)。我不需要能够将触摸事件发送到特定的 HWND,只需将它们发送到桌面上的某些 X/Y 坐标就足以满足我的目的。

我考虑过使用 HARDWAREINPUT 结构和 SendInput 以及直接发送 WM_TOUCH(或 WM_GESTURE?)消息,但在任何一种情况下都不清楚我如何传递有关触摸事件在何处或如何执行的信息。

WM_TOUCH 文档解释了 lParam 参数:

Contains a touch input handle that can be used in a call to GetTouchInputInfo to retrieve detailed information about the touch points associated with this message.

...但不清楚我是否以及如何自己分配这样的 'touch input handle'。它总是只是当前进程地址 space 中的一个普通指针吗?如果是这样,我应该为 TOUCHINPUT 结构的 hSource 字段使用什么值?

您可能正在寻找 Touch injection