Unable to successfully send an array of POINTER_TOUCH_INFO objects as a param to the InjectTouchInput() method RRS feed

  • Question

  • I have been trying to send an array of POINTER_TOUCH_INFO objects to the TouchInjectInput() method, but no action took place. After calling the TouchInjectInput() method, the POINTER_TOUCH_INFO array has only the first index filled and the rest are empty. Can anyone help by pointing out where I made the error?

    Here is the code:

    POINTER_TOUCH_INFO contact[5];
    for(int i= 1; i < 4; i++)
    contact[i] = MakeTouchObject(contact[i-1].pointerInfo.ptPixelLocation.x+10, 480,
    contact[4] = MakeTouchObject(contact[3].pointerInfo.ptPixelLocation.x+10, 480, POINTER_FLAG_UP);

    bRet = InjectTouchInput(5, contact);
    if (!bRet)
    OutputDebugString(L"InjectTouchInput update failed\r\n");

    POINTER_TOUCH_INFO MakeTouchObject(int x, int y, UINT32 flags)
    memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
    contact.pointerInfo.pointerType = PT_TOUCH; //we're sending touch input
    contact.pointerInfo.pointerId = 0; //contact 0
    contact.pointerInfo.ptPixelLocation.x = x;
    contact.pointerInfo.ptPixelLocation.y = y;
    contact.pointerInfo.pointerFlags = flags;
    contact.touchFlags = TOUCH_FLAG_NONE;
    contact.touchMask = TOUCH_MASK_NONE;

    return contact;

    Wednesday, December 7, 2011 5:58 AM


All replies

  • The MakeTouchObject function isn't correct.  It is returning a struct created on its own stack, which won't be valid after the function has returned.  I expect that the POINTER_TOUCH_INFO array is incorrect before the call to InjectTouchInput and not just after.

    I'd pass the address of the POINTER_TOUCH_INFO object to be initialized into MakeTouchObject:

    void MakeTouchObject(POINTER_TOUCH_INFO* contact, int x, int y, UINT32 flags)
       memset(contact, 0, sizeof(POINTER_TOUCH_INFO)); 
       contact->pointerInfo.pointerType = PT_TOUCH; //we're sending touch input 
       contact->pointerInfo.pointerId = 0; //contact 0
       contact->pointerInfo.ptPixelLocation.x = x; 
       contact->pointerInfo.ptPixelLocation.y = y; 
       contact->pointerInfo.pointerFlags = flags; 
       contact->touchFlags = TOUCH_FLAG_NONE; 
       contact->touchMask = TOUCH_MASK_NONE;



    Thursday, December 8, 2011 8:18 PM
  • Many thanks for catching the error, Rob. I should have caught that. Sorry if I'm being too much trouble, but I still am not able to get it working after fixing the MakeTouchObject() function. I tried and failed with a simpler sample of sending a 'down' and following it with a 'up' as an array.

    InitializeTouchInjection(10, TOUCH_FEEDBACK_DEFAULT); 
    POINTER_TOUCH_INFO contact[2];
    MakeTouchObject(&contact[0],150,480,POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT);    	
    MakeTouchObject(&contact[1],150, 480, POINTER_FLAG_UP);
    bRet = InjectTouchInput(2, contact); 

    bRet returns 0 after I pass in the 'contact' array. Just unable to figure this out.

    Wednesday, December 14, 2011 7:36 AM
  • Hi Pushkar,

    I have written an article related to simulation of touch input , please refer this linkhttp://social.technet.microsoft.com/wiki/contents/articles/simulating-touch-input-in-windows-developer-preview-using-touch-injection-api.aspx hopes this has solved all your queries :D

    Sunday, January 1, 2012 8:24 AM
  • Hi Pushkar,

    I got the same error with you.

    bRet = InjectTouchInput(2, contact);

    bRet returns 0 after I pass in the 'contact' array.

    GetLastError() = 5,

    Have you solved the error ? If you have got the error reason, please give some information.


    Monday, December 17, 2012 6:48 AM