问题
How do I detect if a device is touch-enabled in c# for a WinForms app (Not WPF).
I found information on GetSystemMetrics...can't find how to use this in c#.
I Tried using System.Windows.Input.Tablet class..not coming up in c#, even though I am using .Net Framework 4.5.
I Tried using System.Windows.Devices...not coming up in c#, even though I am using .Net Framework 4.5.
I have also checked This and This, which would seem to make this question a duplicate. However, neither of these answers my question.
回答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;
}
回答2:
As taken from this answer
var hasTouch = Windows.Devices.Input
.PointerDevice.GetPointerDevices()
.Any(p => p.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch);
来源:https://stackoverflow.com/questions/27803965/how-do-i-detect-if-a-windows-device-is-touch-enabled