Windows 8 comes with multiple input types. Windows 8 devices often have multi-touch screens that enable users to use multiple fingers simultaneously to produce different input interactions such as tapping, dragging, or pinching. The Windows Runtime has a number of different mechanisms for handling touch input, enabling us to create an immersive experience that we can explore with confidence. This Article covers the basics of using touch input (simulating the touch input via VC++ code) in Windows Developer Preview using C++ by Touch Injection API. For other (consumer preview and release preview) you may need to enable UI access permission( check references for this).

Using this article will help all to create application that will help in simulating the Touch inputs like Tap, Drag, Rotate etc. , Consider an application that will convert users mouse event to touch event for those users who does not have Touch screen monitor. Also this will be of great use for Automating any touch based application on windows 8.


This Article assumes that Reader is updated with these basics requirements

  • Understandings of Microsoft Visual C++
  • Using the code on Windows developer preview
  • Using Visual studio 11 developer preview to compile the code
  • Reader has knowledge of Touch Injection API structure and flags. If not please refer doc1, doc2 or read the references

Touch Interactions

Touch Interactions are a high-level way of interpreting touch input data into a set of common motions such as tapping, dragging, and pinching. Lets Understand some of the common interactions used in Windows Developer Preview which are as follow:


  Input Type 


Tap Single Input One finger touches the screen and lifts up.
Hold Single Input One finger touches the screen and stays in place.
Drag Single Input One or more fingers touch the screen and move in the same direction.
Pinch/Pan Multiple Input Two or more fingers touch the screen and move closer together (Zoom -out) or farther apart (Zoom-in).
Rotate Multiple Input Two or more fingers touch the screen and move in a clockwise or counter-clockwise arc.
Cross-slide Multiple Input  Two finger touches an object and drags it at a right angle to the panning direction.

For windows 8 developer preview this will work as it is but for other windows 8 versions you may need to change UI access permission. Lets see how to simulate these Touch interaction via VC++ code using Touch Injection API.


Simulating Tap

By Tap we mean that it has simply touched any portion of screen. In this use case actor takes two action 

  1. Touch down on screen co-ordinate input
  2. Lifts Up Touch input

To get above done you need to following 5 steps.

1. Create a Win32 application

Create a Win32 application using visual studio 2011 developer preview. ( with No CLR support and without ATL support)

2. Initialize Touch injection

In the WinMain Method Initialize the Touch Injection API refer code below.

InitializeTouchInjection(1, TOUCH_FEEDBACK_DEFAULT); // Here number of contact point is declared as 1.
memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));

3. Define the contact Point 

this definition contains contact type, contact location ,contact area, pressure and orientation .
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.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.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;


4.Implementing use case 1 , Injecting Touching down on screen.

InjectTouchInput(1, &contact); // Injecting the touch down on screen

5] Implementing use case 2 , Injecting Touching Up from screen.

contact.pointerInfo.pointerFlags = POINTER_FLAG_UP;
InjectTouchInput(1, &contact); // Injecting the touch Up from screen

Simulating Hold

 By Hold it mean that Touch is continuously in contact to the screen. In this use case actor takes two action