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.Tablet
class. 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.
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;
}
As taken from this answer
var hasTouch = Windows.Devices.Input
.PointerDevice.GetPointerDevices()
.Any(p => p.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With