我正在尝试使用win32 (Winuser.h) InjectSyntheticPointerInput应用程序接口制作一个钢笔模拟器,以允许我模拟钢笔压力和其他传感器。但是当我尝试注入输入时,它给出了一个错误代码(87:参数不正确)……到目前为止我的代码如下:
#include <iostream>;
#include <Windows.h>;
#include <errhandlingapi.h>;
#include <Winuser.h>;
int main(int argc, char* argv)
{
// Init pointer
const HSYNTHETICPOINTERDEVICE pointer = CreateSyntheticPointerDevice(PT_PEN, 1, POINTER_FEEDBACK_INDIRECT);
if (pointer == nullptr) {
const DWORD err = GetLastError();
std::cout << "Pointer: Error code " << err << std::endl;
return err;
}
// Input creation
POINTER_TYPE_INFO inputInfo[1];
inputInfo[0].type = PT_PEN;
inputInfo[0].penInfo.pointerInfo.pointerType = PT_PEN;
inputInfo[0].penInfo.pointerInfo.pointerId = 0;
inputInfo[0].penInfo.pointerInfo.frameId = 0;
inputInfo[0].penInfo.pointerInfo.pointerFlags = POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN;
inputInfo[0].penInfo.penMask = PEN_MASK_PRESSURE | PEN_MASK_TILT_X | PEN_MASK_TILT_Y;
inputInfo[0].penInfo.pointerInfo.ptPixelLocation.x = 200;
inputInfo[0].penInfo.pointerInfo.ptPixelLocation.y = 200;
inputInfo[0].penInfo.pressure = 1024;
inputInfo[0].penInfo.tiltX = 15;
inputInfo[0].penInfo.tiltY = -26;
// Inject input
if (!InjectSyntheticPointerInput(pointer, inputInfo, 1))
{
const DWORD err = GetLastError();
std::cout << "Input: Error code " << err << std::endl;
return err;
}
// Destroy pointer
DestroySyntheticPointerDevice(pointer);
}当我用调试器打开时,指针的值是0x00000000000000b4,它不是null,但是有这么低的内存地址是正常的吗?这是我的代码的问题所在吗?
如果你能给我一些代码片段或者比微软官方文档更好的解释来说明这个功能,我也会很感激。
发布于 2021-05-22 18:27:21
跟随https://github.com/gsbischoff/usb-pen-injection/blob/master/PenClient.c的126和127行
// These bastards apparently must be zero
PointerInfo.penInfo.pointerInfo.dwTime = 0;
PointerInfo.penInfo.pointerInfo.PerformanceCount = 0;https://stackoverflow.com/questions/67648316
复制相似问题