'How do I detect if a Windows device is touch-enabled
How do I detect if a device is touch-enabled in C# for a WinForms app (Not WPF).
I found information on
GetSystemMetrics. But I can't find how to use this in C#.I tried using
System.Windows.Input.Tabletclass. But it's not coming up in C#, even though I am using .NET Framework 4.5.I tried using
System.Windows.Devices. But it's not coming up in C#, even though I am using .NET Framework 4.5.I have also checked Detect whether a Windows 8 Store App has a touch screen and How to detect a touch enabled device (Win 8, C#.NET), which would seem to make this question a duplicate. However, neither of these answers my question.
Solution 1:[1]
GetSystemMetrics seems to be the right way to go. It should be accessed through P/Invoke like this:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex);
public static bool IsTouchEnabled()
{
const int MAXTOUCHES_INDEX = 95;
int maxTouches = GetSystemMetrics(MAXTOUCHES_INDEX);
return maxTouches > 0;
}
Solution 2:[2]
As taken from this answer
var hasTouch = Windows.Devices.Input
.PointerDevice.GetPointerDevices()
.Any(p => p.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Prikryl |
| Solution 2 | Community |
