Windows CPP InjectSyntheticPointerInput

Viewed 347

I'm trying to make a pen simulator using the win32 (Winuser.h) InjectSyntheticPointerInput API to allow me to simulate Pen Pressure and other sensors. But when I try to Inject the input, it gives me an error code (87: The parameter is incorrect)... My code so far:

#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);
}

When I open with the debugger the pointer has a value of 0x00000000000000b4 it isn't null, but is it normal to have so low memory address? Is that the problem with my code?

I also appreciate if you could point me to code snippets or better explanations than the official microsoft documentation regarding this functionality.

1 Answers
Related