Is there a way to simulate touch events in Windows 8

后端 未结 4 929
我寻月下人不归
我寻月下人不归 2020-12-08 23:11

Is there a way to simulate touch events in Windows 8 (and preferably in windows 7).
I know there is a project called Multi touch vista but I feel its a bit overkill and

相关标签:
4条回答
  • 2020-12-08 23:38

    Creating a virtual Hid driver appears to be the only way.

    0 讨论(0)
  • 2020-12-08 23:44

    I haven't had a chance to try it myself, but according to this article, the simulator included with the Windows 8 Dev Preview allows for simulating multi-touch zoom and rotation gestures using a mouse.

    You can see a demonstration of this at approximately 35:40 of this BUILD conference session: Tools for building Metro style apps

    0 讨论(0)
  • 2020-12-08 23:47

    Further to the solution which points to the C++ Sample code for InjectTouchInput which comes packaged in the User32.dll of Windows 8, the C# solution can be found here:

    InjectTouchInput Windows 8 C# not working (returns false)

    0 讨论(0)
  • 2020-12-09 00:01

    I was looking for something similar and found this article Simulating Touch Input in Windows Developer preview using Touch Injection API and sample code (C++) may answer your question. However, this seems to work only on Windows 8 (not Windows 7).

    It simulates Tap, Hold, Drag, Pinch/Pan, Rotate and Cross-Slide.

    Here is the touch (Tap) code:

    POINTER_TOUCH_INFO contact;
    InitializeTouchInjection(1, TOUCH_FEEDBACK_DEFAULT); // Here number of contact point is declared as 1.
    memset(&contact, 0, sizeof(POINTER_TOUCH_INFO)); 
    
    contact.pointerInfo.pointerType = PT_TOUCH;
    contact.pointerInfo.pointerId = 0;          //contact 0
    contact.pointerInfo.ptPixelLocation.y = 200; // Y co-ordinate of touch on screen
    contact.pointerInfo.ptPixelLocation.x = 300; // X co-ordinate of touch on screen
    
    contact.touchFlags = TOUCH_FLAG_NONE;
    contact.touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
    contact.orientation = 90; // Orientation of 90 means touching perpendicular to screen.
    contact.pressure = 32000; 
    
    // defining contact area (I have taken area of 4 x 4 pixel)
    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_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
    InjectTouchInput(1, &contact); // Injecting the touch down on screen
    
    contact.pointerInfo.pointerFlags = POINTER_FLAG_UP;
    InjectTouchInput(1, &contact); // Injecting the touch Up from screen
    

    Another article: Getting Started with Windows Touch Gestures

    0 讨论(0)
提交回复
热议问题