qakmak
qakmak

Reputation: 1377

Why I can't detect touch screen?

I'm using this C#(wpf) code to detect touch screen on

return Tablet.TabletDevices.OfType<TabletDevice>().Any(dev => dev.Type == TabletDeviceType.Touch)

But it is not working. Tablet.TabletDevices Count is always 0. I'm using extension touch monitor(use USB connect PC for touch detect)

Is there any better way to check if current PC has touch screen or not?

Thanks.

Update1:

I don't know why but even when I remove the touch screen USB and monitor, GetSystemMetrics(SM_MAXIMUMTOUCHES) still returns 1.

Update2:

looks like that is not working, I mean use :

return GetSystemMetrics(SM_MAXIMUMTOUCHES) > 0

Because it's always returning 1, even when I restart computer(win7 OS, laptop computer)

Upvotes: 2

Views: 3437

Answers (1)

baderman
baderman

Reputation: 126

I use a bit different approach, and it works for variety of touchscreens. It works from Win7 and up (as defined here, in section about SM_DIGITIZER setting).

bool touchDevicePresent()
{
    return GetSystemMetrics(SM_DIGITIZER) & NID_READY;
}

Upvotes: 1

Related Questions