Wednesday, January 4, 2012

Detecting a Touch Event in Surface 2.0

Continuing with the Surface 2.0 series, here is a quick post on how you can detect a finger touch on Surface 2.0 and display a message to the user as long and the finger touch is down. As soon as the user lifts its finger, the message disappears.
In order to implement this sample you need to have all the Surface 2.0 SDK, tools and runtime installed. Once all that is done you are good to go. Fire up Visual Studio and select the Surface 2.0 templates. Use the Surface application template and create the new project.
The default template will create the window activation events by default and the logic to add and remove the event handlers as necessary. In order to display the message to the user, change the default “<Grid />” element in the “SurfaceWindow1.xaml” file for the following:
The label will be hidden by default. Now, navigate to the code behind file of the main window named “SurfaceWindow1.xaml.cs” and add the following at the end of it:
Before running the application, make sure that the Surface Input Simulator is running, so the application can actually receive input. You will need to select the Finger input emulation once the app is running to emulate a finger touch. To run the Input Simulator, select All Programs | Microsoft Surface 2.0 SDK | Tools | Input Simulator.
You are now ready to go. Hit F5 to run the application, select the finger input simulation method and start touching the surface. You will see the “Touch Detected !” message every time you touch the surface and the message will disappear once you lift the finger.
Cheers and happy Surface 2.0 coding !

No comments:

Post a Comment