2

在 Windows 8 中切换应用程序的一种简单方法是使用触摸屏“向右滑动”(将一根手指放在屏幕左侧并将其向右移动几个像素)。我正在尝试使用Touch Injection API模拟此行为,但未调用切换应用程序行为,尽管反馈显示滑动实际上正在发生。这是我运行的代码:

int main()
{ 
    //Screen Resolution 1366x768
    BOOL ret = TRUE;

    //init
    InitializeTouchInjection(10, TOUCH_FEEDBACK_INDIRECT);
    POINTER_TOUCH_INFO contact = {0};
    memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));

    contact.pointerInfo.pointerType = PT_TOUCH;
    contact.pointerInfo.pointerId = 0;

    //set start point (a point at the left side of the screen)
    contact.pointerInfo.ptPixelLocation.y = 768/2;
    contact.pointerInfo.ptPixelLocation.x = 0;

    contact.touchFlags = TOUCH_FLAG_NONE;
    contact.touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
    contact.orientation = 90;
    contact.pressure = 32000;

    contact.rcContact.top = contact.pointerInfo.ptPixelLocation.y -2;
    contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.y + 2;
    contact.rcContact.left = contact.pointerInfo.ptPixelLocation.x -2;
    contact.rcContact.right = contact.pointerInfo.ptPixelLocation.x + 2;

    //set flags for "start touch"
    contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;

    ret = InjectTouchInput(1, &contact);

    cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
    if(ret != TRUE)
    {
        cout << "Error 1: " << GetLastError() <<endl;
        return 1;
    }

    for(int i=0; i<100; i++)
    {
        //set flags for "update"
        contact.pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;

        //move the location one pixel right
        contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.x++;

        ret = InjectTouchInput(1, &contact);

        cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
        if(ret != TRUE)
        {
            cout << "Error 2: " << GetLastError() <<endl;
            return 1;
        }
    }

    //set flags for "end touch"
    contact.pointerInfo.pointerFlags = POINTER_FLAG_UP;

    ret = InjectTouchInput(1, &contact);

    cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
    if(ret != TRUE)
    {
        cout << "Error 3: " << GetLastError() <<endl;
        return 1;
    }
    return 0;
}

有什么想法为什么这段代码没有按预期运行?

顺便说一句,尝试“向左滑动”打开 Charms-Bar 时也会发生同样的情况

代码写在这篇文章上

4

0 回答 0