首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows CPP InjectSyntheticPointerInput

Windows CPP InjectSyntheticPointerInput
EN

Stack Overflow用户
提问于 2021-05-22 18:15:40
回答 1查看 135关注 0票数 2

我正在尝试使用win32 (Winuser.h) InjectSyntheticPointerInput应用程序接口制作一个钢笔模拟器,以允许我模拟钢笔压力和其他传感器。但是当我尝试注入输入时,它给出了一个错误代码(87:参数不正确)……到目前为止我的代码如下:

代码语言:javascript
复制
#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,但是有这么低的内存地址是正常的吗?这是我的代码的问题所在吗?

如果你能给我一些代码片段或者比微软官方文档更好的解释来说明这个功能,我也会很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-22 18:27:21

跟随https://github.com/gsbischoff/usb-pen-injection/blob/master/PenClient.c的126和127行

代码语言:javascript
复制
        // These bastards apparently must be zero
        PointerInfo.penInfo.pointerInfo.dwTime = 0;
        PointerInfo.penInfo.pointerInfo.PerformanceCount = 0;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67648316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档