Search code examples
c#wpfwindows-10touchwindows-10-desktop

Capture touch input on the screen in windows device


Is there any way to capture touch input on the screen (outside application frame) in windows device?

I'm working on a WPF application and can retrieve the touch input if it only occurs within the application frame. Also, is there a way to register the touch input even when the application is minimized?


Solution

  • There's no built-in method of the WPF framework that lets you listen for input outside of the application. If you want to do that, you'll have to get into p/invoke territory.

    Specifically you'll need to create a hook. You'll want to look at the SetWindowsHookEx method and either the WH_MOUSE or WH_MOUSE_LL hooks.

    Since you're dealing with touch inputs, this answer might have some useful information for you:

    The lParam argument of your hookProc callback is a pointer to an MSLLHOOKSTRUCT. It contains a very poorly documented dwExtraInfo variable, which tells you whether it was generated from a touch.

    If all of the bits in 0xFF515700 are set in dwExtraInfo, then the callback was invoked in response to a touch.