Wednesday, March 14, 2012

How to get Input From Entire Screen on Microsoft Surface

On Microsoft Surface, in order to detect TouchPoint input, you must create a new instance of the TouchTarget class (a.k.a. ContactTarget prior to v2.0)

The first parameter to the TouchTarget constructor is an IntPtr handle to an application window.  If you pass in a handle to a window running in a different process, you'll get an error.  This originally led me to believe that in order to detect touch input, you had to have a windowed application, and there was no option to detect touches occurring outside that window.

Fortunately, I was incorrect.

To use the whole screen as your TouchTarget, simply pass in IntPtr.Zero as your window handle, like so:

          new TouchTarget(IntPtr::Zero, Core::EventThreadChoice::OnBackgroundThread ); 

If you do this, keep in mind that TouchPoints you receive will have x and y coordinates relative to the screen, not your application window.  

No comments:

Post a Comment