1

I am using the InjectTouchInput() API on Windows 10 to inject touch events from a separate digitiser. That works well (multi-touch etc.). There are quite a few examples out there of using the API for that, i.e. using a pointer type of PT_TOUCH, including one from Microsoft, so it wasn't too difficult to customise them to my needs.

However, I have not found any example of using other pointer types, especially PT_PEN - which I need when the digitiser gives me pen inputs. (I'd also be interested in PT_MOUSE, mainly to avoid having to use SendInput() or mouse_event().)

Whenever I call InjectTouchInput() with PT_PEN, it fails with ERROR_INVALID_PARAMETER. I've tried quite a few combinations of fields to set, but nothing (so far) works. The MSDN documentation doesn't describe what to do for PT_PEN (it doesn't describe much for PT_TOUCH, but at least there's one sample), so it's quite difficult to know what fields should be set, which ones should be ignored, any specific sequence of operations, etc. I've been scouring the net, but couldn't find any example of PT_PEN use.

Does anybody have sample code or know where to find any, knowledge of where useful documentation is located, or knows how InjectTouchInput() is supposed to be used for PT_PEN (and PT_MOUSE)?

4

2 回答 2

1

事实证明,这InjectTouchInput()确实只适用于触摸输入——而不是笔、鼠标或通用指针。

您可能会说这很明显,因为您将一组POINTER_TOUCH_INFO条目传递给 API,但是由于文档POINTER_TOUCH_INFO(以及所有后续文档)描述的内容主要是从解释给定内容的人那里看到的,而不是内容他正在尝试设置,并且 POINTER_INFO(中的第一个元素POINTER_TOUCH_INFO)可以指定一个指针类型PT_POINTER, PT_TOUCH, PT_PEN, PT_MOUSE, or PT_TOUCHPAD,所以很自然地想“等等,我可以注入所有这些不同类型的指针!

当然,所有指针类型尽管有POINTER_INFO共同点,但参数略有不同。例如,有orientationand pressurefor PT_TOUCH(in POINTER_TOUCH_INFO), but tiltX, tiltY, rotation, and pressurefor PT_PEN(in POINTER_PEN_INFO);但是鉴于指针类型始终是结构中的第一个字段,很容易确定哪些信息是相关的。

可以InjectTouchInput()POINTER_PEN_INFO条目而不是条目 POINTER_TOUCH_INFO吗?不,它不能——我试过了,以防万一。

微软似乎错失了从一开始就使 API 更通用并接受所有支持的指针类型的机会,而不是仅限于触摸输入。至少,笔注入应该是简单的,因为有一个POINTER_PEN_INFO结构(除了 之外,我还没有找到其他指针类型的结构POINTER_TOUCH_INFO)。

从 2014 年开始,该线程的中途提到“没有用于笔注入的 [...] API ”,从那时起事情就没有改善,因此仍然需要用于笔注入的驱动程序。话虽如此,Windows UI 自动化 API 显然可以注入所有指针类型(以及用于启动的游戏手柄),但这仅受 Windows 10 周年纪念版支持(我还没有尝试过)。

于 2017-08-24T17:01:59.440 回答
1

我们可以使用InputInjector.InjectPenInput实现笔输入注入

并且win32中没有用于笔注入的公共api。如果您的系统是 Windows 10 版本 1809,则可以使用InjectSyntheticPointerInput 。

于 2018-11-21T09:01:28.980 回答