2 years ago

#23420

test-img

Filipe QDL

How to inject multitouch with InjectSyntheticPointerInput

Im trying to implement the pinch-example but want to use the InjectSyntheticPointerInput function since this is for a project that receives stylus and touch input from another device (tablet/notebook/etc.). Since injecting the received touches one after another results in this (multiple pointers created but multitouch geastures not working) i think i need to inject the touches as an array of POINTER_TYPE_INFOs. Im using the following code to test that but get Error 0x57 (ERROR_INVALID_PARAMETER) when trying to inject more than one pointer.


#include <iostream>
#include <Windows.h>

#define POINTER_HOVER POINTER_FLAG_INRANGE | POINTER_FLAG_UPDATE
#define POINTER_DOWN  POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN
#define POINTER_WRITING POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE
#define POINTER_UP POINTER_FLAG_INRANGE | POINTER_FLAG_UP

int main()
{
    auto handle = CreateSyntheticPointerDevice(PT_TOUCH, 2, POINTER_FEEDBACK_DEFAULT);
    if (!handle) {
        std::printf("Creating Pointer failed\n");
        return 1;
    }
    if (InitializeTouchInjection(2, TOUCH_FEEDBACK_DEFAULT)) {

        std::printf("TouchInjectionInitialized\n");

        int x[2] = { 500, 600 };
        int y[2] = { 500, 500 };
        //POINTER_TYPE_INFO* pt= (POINTER_TYPE_INFO*)malloc(sizeof(POINTER_TYPE_INFO ) * 2);
        POINTER_TYPE_INFO pt[2] = {};
        if (!pt) {
            return 1;
        }
        for (auto i = 0; i < 2; i++) {
            pt[i] = {};
            pt[i].type = PT_TOUCH;
            pt[i].touchInfo = {};
            pt[i].touchInfo.pointerInfo = {};
            pt[i].touchInfo.pointerInfo.pointerId = i;
            pt[i].touchInfo.pointerInfo.dwTime = 0;
            pt[i].touchInfo.pointerInfo.PerformanceCount = 0;
            pt[i].touchInfo.pointerInfo.pointerType = PT_TOUCH;
            pt[i].touchInfo.pointerInfo.ptPixelLocation = POINT{ x[i],y[i] };
            pt[i].touchInfo.pointerInfo.pointerFlags = POINTER_HOVER;
        }

        if (InjectSyntheticPointerInput(handle, pt, 2)) {
            std::printf("POINTER_START injected\n");
            
            pt[0].touchInfo.pointerInfo.pointerFlags = POINTER_DOWN;
            pt[1].touchInfo.pointerInfo.pointerFlags = POINTER_DOWN;

            if (InjectSyntheticPointerInput(handle,pt, 2)) {
                std::printf("POINTER_DOWN injected\n");

                pt[0].touchInfo.pointerInfo.pointerFlags = POINTER_WRITING;
                pt[1].touchInfo.pointerInfo.pointerFlags = POINTER_WRITING;
                for (auto i = 0; i < 10; i++) {
                    pt[0].touchInfo.pointerInfo.ptPixelLocation = POINT{ x[0] + i * 10,y[0]};
                    pt[0].touchInfo.pointerInfo.ptPixelLocation = POINT{ x[1] - i * 10,y[1] };
                    if (InjectSyntheticPointerInput(handle, pt, 2)) {
                        std::printf("POINTER_WRITING injected\n");
                    }
                    Sleep(100);
                }

                pt[0].touchInfo.pointerInfo.pointerFlags = POINTER_UP;
                pt[1].touchInfo.pointerInfo.pointerFlags = POINTER_UP;
                if (InjectSyntheticPointerInput(handle, pt, 2)) {
                    std::printf("POINTER_UP injected\n");
                }

                pt[0].touchInfo.pointerInfo.pointerFlags = POINTER_HOVER;
                pt[1].touchInfo.pointerInfo.pointerFlags = POINTER_HOVER;
                if (InjectSyntheticPointerInput(handle, pt, 2)) {
                    std::printf("POINTER_HOVER injected\n");
                }
            }
        }
    }
}

InjectSyntheticPointerInput(handle, pt, 1) works perfectly fine, but InjectSyntheticPointerInput(handle, pt, 2) is failing with ERROR_INVALID_PARAMETER

The POINTER_TYPE_INFO structs also seem to be ok since injecting either one of them works aswell.

c++

windows

winapi

touch

multi-touch

0 Answers

Your Answer

Accepted video resources