Search code examples
windowswinapitouchgesture

How can I detect touch input events using hooks, in Windows 10?


I am unable to figure out how I can detect touch events, that are made anywhere on a touch screen monitor, using hooks. Is that even possible?


Solution

  • This may not be exactly what you're looking for, but there are a few ways to set hooks:

    1. SetWinEventHook (active accessibility hook). Pros: is a supported high-level way to get events from Windows. Cons: can slow down applications, especially if you are running an "out of context" hook.
    2. SetWindowsHookEx. Pros: very low-level hooking into applications. Cons: doesn't support out of context hooks so you need to write your own IPC and also sometimes unreliable (e.g. sometimes you miss events in Command Prompt).

    Looking through the first API I don't see anything specific to touch (although I would encourage you to grab the most recent Windows SDK and look at the different events). You could, however, simply look for cursor position changes to know where the user most recently touched.

    The second API may give you the kind of control you want because you can use a WH_CALLWNDPROC hook to trap touch events. But then again, a window only receives touch-related messages if they mark themselves as touch-aware. So even this may not do what you want.