📜 ⬆️ ⬇️

Handling touch input in Windows 8 applications

Even the most serious developers who write in assembler and know by heart all keyboard shortcuts will not be able to challenge the fact that more and more devices and their users support touch screen input, so the processing of touch interaction methods in applications is becoming increasingly important. Standard controls and Windows 8 templates work well with touch input - if you use only them, you do not need to understand the technical details. If you are dealing with classic applications or want to develop your own controls (for example, for a game), then you need to know how to properly handle touch input.

Applications running on Windows 7 will continue to work with the following features:

In both cases, you might consider refining your application using the new Windows 8 input APIs, as they will help ensure consistency with other applications and generally improve user experience.
If your application was not originally designed to handle touch input, you may also need to refine the user interface to make it more suitable for touch control: increase the size of controls, remove unnecessary elements, etc.

Development for touch control without touch device

If you do not have touch devices, you can try out your classic application or the Windows Store app in the Windows 8 simulator, which is included with Visual Studio 2012 on the Windows 8 platform.
This program is located in the folder C: \ Program Files (x86) \ Common Files \ Microsoft Shared \ Windows Simulator \ 11.0 \ Microsoft.Windows.Simulator.exe .
It can run any application, as in a normal session:


')
Windows 8 Store apps can also be launched directly in the simulator from Visual Studio:



Touch interaction in Windows 8

For your application to be user-friendly, the gestures used in it must match the standard gestures in the OS:



Pointer Entry Principle

Processing applications for multiple input methods at once can greatly complicate things. Fortunately, in Windows 8, Microsoft implemented the combined input using the Pointer element:



The Pointer input method combines input methods with the mouse, pen and touches and is an abstraction of these input methods, which makes it possible to process all methods by writing code only once.
Pointer events are the easiest thing you'll come across. You can get them for any element of the user interface of Windows 8 XAML, as well as for ICoreWindow. From the HTML5 side, these elements are available, but their names are somewhat different. They have the prefix MS: MSPointerDown, MSPointerMove, MSPointerUp.

Win32 pointer events are equivalent to WM_POINTERXXX messages, which you can get in the Win32 callback function. By default, in Win32 applications, the WM_POINTERXXX messages do not include mouse messages. To get really merged pointer messages, you must first call EnableMouseInPointer (true).

Manipulation events can also provide scaling, rotation, and scrolling information. In addition, they provide inertia data. They can be configured using the ManipulationMode to switch inertia. You can allow only certain types of interaction / add restrictions (for example, guides for conversion into motion along the X / Y axis).

In Windows 8 Windows Store apps written in HTML5 / JavaScript, you can use the WinRT GestureRecognizer method to access these events.

Overview of the Windows 8 APIs



If the object you are working with does not switch gesture events, you can send pointer events to the GestureRecognizer interface. GestureRecognizer will switch selected gesture and manipulation events, as well as drag and cross-scroll events.

Win32 InteractionContext is equivalent to the GestureRecognizer in the Windows Runtime API. The Interaction Context object switches INTERACTION_CONTEXT_OUTPUT_CALLBACK associated with other gestures and manipulations.

In addition, the InkRecognizer interface can be embedded in the touch application. It allows you to recognize handwriting in classic applications and in Windows 8 Store apps.
You can also embed touch events from classic applications using the Touch Injection API API .

Full version of the article can be found on the site Intel Developer Zone .

Source: https://habr.com/ru/post/220381/


All Articles