I am trying to test the Touch Injection API for injecting multiple strokes when using Windows 8. To do this, I create 5 contacts and then simulate a hang, and then drag and drop.
This is great for one-touch contact. However, nothing changes when I add 4 more contacts, that is, it produces the same thing as if there was only one contact. (I test by opening Paint on the right side of the screen and a visual studio on the left. Then, when the program starts the line, it is drawn diagonally in the paint window). When I run GetLastError () after InitializeTouchInjection, it gives me 5, which is an invalid access error.
Is there a flag I should use? Should my computer install a specific driver? What is wrong here?
Here is the code:
#include <windows.h>
void Drag(int x, int y){
POINTER_TOUCH_INFO contact_[5];
BOOL bRet = TRUE;
InitializeTouchInjection(5, TOUCH_FEEDBACK_DEFAULT);
for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerId = c;
contact.pointerInfo.ptPixelLocation.y = y;
contact.pointerInfo.ptPixelLocation.x = x+50*c;
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;
contact.pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE ;
}
InjectTouchInput(5, contact_);
Sleep(20);
for(int i=0;i<200;i++)
{
for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
contact.pointerInfo.ptPixelLocation.x--;
contact.pointerInfo.ptPixelLocation.y++;
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;
if (i==100)
contact.pointerInfo.pointerFlags = POINTER_FLAG_INCONTACT | POINTER_FLAG_INRANGE | POINTER_FLAG_DOWN;
if (i>100)
contact.pointerInfo.pointerFlags = POINTER_FLAG_INCONTACT | POINTER_FLAG_INRANGE | POINTER_FLAG_UPDATE;
}
InjectTouchInput(5, contact_);
Sleep(20);
}
for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
contact.pointerInfo.pointerFlags = POINTER_FLAG_INRANGE | POINTER_FLAG_UP;
}
InjectTouchInput(5, contact_);
Sleep(10);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Drag(1300,500);
}
source
share