C++ 如何在Windows 8.1 C++;

C++ 如何在Windows 8.1 C++;,c++,windows-8.1,multi-touch,C++,Windows 8.1,Multi Touch,我一直在尝试在Windows8上注入个人联系人(触摸事件)。我正在使用所描述的InjectTouchInput,因此我能够使用下一个代码注入两个联系人: #include "stdafx.h" #include <iostream> #include <string> #include <sstream> #include <windows.h> using namespace std; class calculate { POINTE

我一直在尝试在Windows8上注入个人联系人(触摸事件)。我正在使用所描述的InjectTouchInput,因此我能够使用下一个代码注入两个联系人:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include <windows.h>

using namespace std;

class calculate
{
    POINTER_TOUCH_INFO contact[2];

public:
    calculate(int m);
    void setDots(long x, long y, long x2, long y2, int opt, string num_dots);
};

calculate::calculate(int m)
{
}

void calculate::setDots(long x, long y, long x2, long y2, int opt, string num_dots)
{

    switch (opt)
    {
        case 0:
            InitializeTouchInjection(2, TOUCH_FEEDBACK_INDIRECT);
            memset(&contact[0], 0, sizeof(POINTER_TOUCH_INFO));
            memset(&contact[1], 0, sizeof(POINTER_TOUCH_INFO));

            contact[0].pointerInfo.pointerType = PT_TOUCH;
            contact[0].pointerInfo.pointerId = 0;          //Id 0 for contact 0
            contact[0].pointerInfo.ptPixelLocation.y = y;
            contact[0].pointerInfo.ptPixelLocation.x = x;

            contact[0].touchFlags = TOUCH_FLAG_NONE;
            contact[0].touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
            contact[0].orientation = 90;
            contact[0].pressure = 32000;
            contact[0].rcContact.top = contact[0].pointerInfo.ptPixelLocation.y - 2;
            contact[0].rcContact.bottom = contact[0].pointerInfo.ptPixelLocation.y + 2;
            contact[0].rcContact.left = contact[0].pointerInfo.ptPixelLocation.x  - 2;
            contact[0].rcContact.right = contact[0].pointerInfo.ptPixelLocation.x  + 2;

            contact[1].pointerInfo.pointerType = PT_TOUCH;
            contact[1].pointerInfo.pointerId = 1;          //Id 0 for contact 1
            contact[1].pointerInfo.ptPixelLocation.y = y2;
            contact[1].pointerInfo.ptPixelLocation.x = x2;

            contact[1].touchFlags = TOUCH_FLAG_NONE;
            contact[1].touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
            contact[1].orientation = 90;
            contact[1].pressure = 32000;
            contact[1].rcContact.top = contact[1].pointerInfo.ptPixelLocation.y - 2;
            contact[1].rcContact.bottom = contact[1].pointerInfo.ptPixelLocation.y + 2;
            contact[1].rcContact.left = contact[1].pointerInfo.ptPixelLocation.x  - 2;
            contact[1].rcContact.right = contact[1].pointerInfo.ptPixelLocation.x  + 2;
        break;
        case 1: 
            contact[0].pointerInfo.ptPixelLocation.y = y;
            contact[0].pointerInfo.ptPixelLocation.x = x;
            contact[1].pointerInfo.ptPixelLocation.y = y2;
            contact[1].pointerInfo.ptPixelLocation.x = x2;
            contact[0].pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
            contact[1].pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
        break;
        case 2:
            /*if I inject this flag to first contact [0], both points stopped, but I'm able to inject this flag to the second contact [1] and all is OK*/
            //contact[0].pointerInfo.pointerFlags = POINTER_FLAG_UP;

            contact[0].pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
            contact[1].pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
            //contact[1].pointerInfo.pointerId = 0;  
            //contact[0].pointerInfo.pointerId = 1;   
            contact[0].pointerInfo.ptPixelLocation.x =x;
            contact[0].pointerInfo.ptPixelLocation.y =y;
            contact[1].pointerInfo.ptPixelLocation.x =x2;
            contact[1].pointerInfo.ptPixelLocation.y =y2;
            //num_dots = "single";
        break;
        case 3:
            contact[0].pointerInfo.pointerFlags = POINTER_FLAG_UP;
            contact[1].pointerInfo.pointerFlags = POINTER_FLAG_UP;
        break;
    }

    bool s;
    //check how many points to inject
    if(num_dots == "single")
        s = InjectTouchInput(1, contact);
    else
        s = InjectTouchInput(2, contact);

    if(!s)
    {
        LPWSTR str = new wchar_t[255];
        auto t = GetLastError();
        wsprintf(str, L"error: %d\n", t);
        OutputDebugString(str);
        wsprintf(str, L" action: %d\n", opt);
        OutputDebugString(str);
    }
    else
    {
        LPWSTR str = new wchar_t[255];
        auto t = GetLastError();
        wsprintf(str, L"action %d\n", opt);
        OutputDebugString(str);
    }
    if(opt == 2)
        Sleep(20);
}


int c =0;
int
WINAPI WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR lpCmdLine,
    _In_ int nShowCmd)
{

    bool g = true;
    POINT ipoint;
    POINT point;
    calculate set(0);
    if (GetCursorPos(&ipoint)) 
        set.setDots(ipoint.x, ipoint.y, 0,0,0, "single");//initialize both points


    do
    {

        if (GetCursorPos(&point)) {   

            //stop the loop pressing right click
            if((GetKeyState(VK_RBUTTON) & 0x100) != 0)
                g = false;
            if((GetKeyState(VK_LBUTTON) & 0x100) != 0)
            {
                if(c<1)
                {                   

                    if((GetKeyState(VK_LSHIFT) & 0x100) != 0)//injecting DOWN event
                        set.setDots(point.x, point.y, point.x - 50, point.y + 50, 1, "two");
                    else
                        set.setDots(point.x, point.y, 0, 0, 1, "single");
                }
                else
                {
                    if((GetKeyState(VK_LSHIFT) & 0x100) != 0)//injecting UPDATE event (on move)
                        set.setDots(point.x, point.y, point.x - 50, point.y + 50, 2, "two");
                    else
                        set.setDots(point.x, point.y, 0,0,2, "single");
                }
                c++;
            }
            else
            {
                /*if((GetKeyState(VK_LSHIFT) & 0x100) != 0)
                    set.setDots(0,0,0,0,3, "two");
                else
                    set.setDots(0,0,0,0,3, "single");*/
                c = 0;
            }     
        }
    } while (g);


}
#包括“stdafx.h”
#包括
#包括
#包括
#包括
使用名称空间std;
类计算
{
指针触摸信息联系人[2];
公众:
计算(int m);
无效设置点(长x、长y、长x2、长y2、int opt、字符串num_点);
};
计算::计算(int m)
{
}
void calculate::设置点(长x、长y、长x2、长y2、int opt、字符串num_点)
{
开关(opt)
{
案例0:
初始化触摸注射(2,触摸反馈间接);
memset(&contact[0],0,sizeof(指针触摸信息));
memset(&contact[1],0,sizeof(指针触摸信息));
联系人[0]。pointerInfo.pointerType=PT\u TOUCH;
联系人[0]。pointerInfo.pointerId=0;//联系人0的Id为0
联系人[0]。pointerInfo.ptPixelLocation.y=y;
联系人[0]。pointerInfo.ptPixelLocation.x=x;
联系人[0]。touchFlags=TOUCH\u FLAG\u NONE;
触点[0]。touchMask=触摸屏|触摸屏|接触区域|触摸屏|方向|触摸屏|压力;
触点[0]。方向=90;
触点[0],压力=32000;
联系人[0]。rcContact.top=联系人[0]。pointerInfo.ptPixelLocation.y-2;
联系人[0]。rcContact.bottom=联系人[0]。pointerInfo.ptPixelLocation.y+2;
联系人[0]。rcContact.left=联系人[0]。pointerInfo.ptPixelLocation.x-2;
联系人[0]。rcContact.right=联系人[0]。pointerInfo.ptPixelLocation.x+2;
联系人[1]。pointerInfo.pointerType=PT\u TOUCH;
联系人[1]。pointerInfo.pointerId=1;//联系人1的Id为0
联系人[1]。pointerInfo.ptPixelLocation.y=y2;
联系人[1]。pointerInfo.ptPixelLocation.x=x2;
联系人[1]。touchFlags=TOUCH\u FLAG\u NONE;
触点[1]。touchMask=触摸屏|触摸屏|接触区域|触摸屏|方向|触摸屏|压力;
触点[1]。方向=90;
触点[1],压力=32000;
联系人[1]。rcContact.top=联系人[1]。pointerInfo.ptPixelLocation.y-2;
联系人[1]。rcContact.bottom=联系人[1]。pointerInfo.ptPixelLocation.y+2;
联系人[1]。rcContact.left=联系人[1]。pointerInfo.ptPixelLocation.x-2;
联系人[1]。rcContact.right=联系人[1]。pointerInfo.ptPixelLocation.x+2;
打破
案例1:
联系人[0]。pointerInfo.ptPixelLocation.y=y;
联系人[0]。pointerInfo.ptPixelLocation.x=x;
联系人[1]。pointerInfo.ptPixelLocation.y=y2;
联系人[1]。pointerInfo.ptPixelLocation.x=x2;
联系人[0]。pointerInfo.pointerFlags=POINTER_FLAG_DOWN | POINTER_FLAG_in range | POINTER_FLAG_in contact;
联系人[1]。pointerInfo.pointerFlags=POINTER_FLAG_DOWN | POINTER_FLAG_in range | POINTER_FLAG_in contact;
打破
案例2:
/*如果我将此标志注入第一个触点[0],两个点都会停止,但我可以将此标志注入第二个触点[1],一切正常*/
//联系人[0]。pointerInfo.pointerFlags=POINTER\u FLAG\u UP;
联系人[0]。pointerInfo.pointerFlags=POINTER_-FLAG_-UPDATE | POINTER_-FLAG_-INRANGE | POINTER_-FLAG_-INCONTACT;
联系人[1]。pointerInfo.pointerFlags=POINTER_-FLAG_-UPDATE | POINTER_-FLAG_-INRANGE | POINTER_-FLAG_-INCONTACT;
//联系人[1]。pointerInfo.pointerId=0;
//联系人[0]。pointerInfo.pointerId=1;
联系人[0]。pointerInfo.ptPixelLocation.x=x;
联系人[0]。pointerInfo.ptPixelLocation.y=y;
联系人[1]。pointerInfo.ptPixelLocation.x=x2;
联系人[1]。pointerInfo.ptPixelLocation.y=y2;
//num_dots=“单个”;
打破
案例3:
联系人[0]。pointerInfo.pointerFlags=POINTER\u FLAG\u UP;
联系人[1]。pointerInfo.pointerFlags=POINTER\u FLAG\u UP;
打破
}
布尔s;
//检查要注入多少点
如果(点数=“单个”)
s=输入(1,触点);
其他的
s=输入(2,触点);
如果(!s)
{
LPWSTR str=新的wchar_t[255];
auto t=GetLastError();
wsprintf(str,L“错误:%d\n”,t);
OutputDebugString(str);
wsprintf(str,L“操作:%d\n”,opt);
OutputDebugString(str);
}
其他的
{
LPWSTR str=新的wchar_t[255];
auto t=GetLastError();
wsprintf(str,L“操作%d\n”,opt);
OutputDebugString(str);
}
如果(opt==2)
睡眠(20);
}
int c=0;
int
WINAPI WinMain(
_在uhinstance中,
_在当前情况下,
_在LPSTR lpCmdLine中,
_In_uintnshowcmd)
{
bool g=真;
点i点;
点-点;
计算集(0);
if(GetCursorPos(&ipoint))
set.setDots(ipoint.x,ipoint.y,0,0,0,“单”);//初始化两个点
做
{
if(GetCursorPos(&point)){
//按右键单击停止循环
if((GetKeyState(VK_RBUTTON)&0x100)!=0)
g=假;
if((GetKeyState(VK_LBUTTON)&0x100)!=0)
{
if(c)