Is it possible to let my c# wpf program know if the user has a touchscreen or not?

放肆的年华 提交于 2019-11-26 17:14:33

问题


I've got an login application that has a swipe system that people only can use when they have a touchscreen. They can login by swiping their personal pattern swipe code.

Is it possible to check in C# or WPF if the user has a touchscreen? Even when he isn't using touch on it at that time?


回答1:


Within C# code to find out if a touch screen exists (doesn't check if its a single or multi-touch device though) by the using System.Windows.Input namespace in PresentationCore.

    public bool HasTouchInput()
    {
        foreach (TabletDevice tabletDevice in Tablet.TabletDevices)
        {
            //Only detect if it is a touch Screen not how many touches (i.e. Single touch or Multi-touch)
            if(tabletDevice.Type == TabletDeviceType.Touch)
                return true;
        }

        return false;
    }



回答2:


I don't think there's anything available in managed code but you could use P/Invoke on Win32_DesktopMonitor. For more information see msdn.

I found this blog-post that might be of help even though it's on Windows CE: http://blog.nerdbank.net/2006/10/platform-detection-iii-how-to-detect.html




回答3:


There is IInkTablet2 COM interface in Windows XP Tablet PC Edition or managed wrapper Microsoft.Ink.Tablet class for non-WPF applications. But it most of touch screen drivers are "mouse" drivers and can't be detected in this way.



来源:https://stackoverflow.com/questions/5673556/is-it-possible-to-let-my-c-sharp-wpf-program-know-if-the-user-has-a-touchscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!