Virtual Trackpad

Published: 07/17/2013   Last Updated: 07/17/2013



When games specifically built for PCs are run on a Win 8 tablet without a physical mouse, the tablet’s small screen and finger’s large touch area makes it difficult to select the correct GUI element when they are placed close together. The goal of this sample is to demonstrate how to implement an on screen virtual track pad and use it to control small UI elements in a game in the absence of a physical mouse.

The sample uses a Windows message hook to intercept WM_POINTER messages in the message queue. If the users touches the screen inside the on screen track pad region, the sample generates appropriate WM_MOUSEMOVE, WM_LBUTTONDOWN / UP, WM_MBUTTONDOWN / UP and WM_RBUTTONDOWN / UP messages. Here is the screen shot of the sample.


As shows in figure above,

  • TP: represents the track pad region and can be used to move the mouse cursor.
  • LB: represents the left mouse button
  • MB: represents the middle mouse button
  • RB: represents the right mouse buttoon

Virtual Track pad usage model:

  • To move the mouse cursor: Touch inside the TP region of the on screen track pad and move your finger in the direction that you want the mouse cursor to move on the screen.
  • Left mouse button click : Single tap the on screen left mouse button
  • Middle mouse button click : Single tap the on screen middle mouse button
  • Right mouse button click : Single tap the on screen right mouse button

Left mouse button click + drag: The click + drag event can be used to move the slider or the camera in the scene.The conventional usage model for a click + drag is to hold the left mouse button down while moving the mouse cursor. This two finger usage model is difficult to use on a touch screen and so we provide an alternate usage model in addition to the conventional usage model. If the user holds down the on screen left mouse button down for a small duration of time (1000 clock cycles) then, even when he release his finger the message hook procedure simulates a WM_LBUTTONDOWN for the user. This is shown in the figure below where the LB region of the track pad is darker in color than the other regions. The user can now use the TP region of the track pad to move the mouse cursor and generate the click + drag event. When the click + drag event is completed the user will have to again single tap the left mouse button to simulate a WM_LBUTTONUP message.

Use the show track pad checkbox to enable / disable the display of the virtual track pad. When the track pad is disabled the sample disables processing “touch” events

Attachment Size 38.7 MB

Product and Performance Information


Performance varies by use, configuration and other factors. Learn more at