Capturing touch events with LowLevelMouseProc does not work for all applications
Asked Answered
S

0

6

tldr: i am using LowLevelMouseProc to capture all touch events from a touch screen. This works for my application and some other applications, but unfortunately not for all apps. Can someone explain me why?

Complete story:

I have a C# application that uses LowLevelMouseProc + SetWindowsHookEx to detect touch positions on a touch screen. The hook allows me to capture all touches made on the touch screen

  • if my application is in the foreground
  • for the Windows desktop (my application is minimized)
  • for some applications, e.g. Visual Studio or Firefox

Unfortunately, this mechanism does not work for all apps, e.g. it does not capture any touches made in the display region covered by Google Chrome.

  1. Does that mean that, for example Google Chrome, already consumes the touch event and does not call subsequent event handlers (including my hook)? Someone else has made a similar observation? Can anyone explain this behavior?

Update: The touch hooks works even in Chrome, but only in the area of context menus (e.g. in the popup that you get when right clicking on website). This might support the theory that Chrome consumes the touch events

Others emphasized that it is required that the LowLevelMouseProc callback is in a separate DLL. Furthermore, others say that also required that the external application and the DLL have the same architecture (x86, x64). See related post here.

  1. In my project, the all touch event processing methods are in a separate DLL. Additionally, the callback has its own thread. As said above, this works nicely for some applications but not all, independent on whether my project (*.exe + *.dll) is compiled as an x86/x64 application.

Interestingly, the hook works for all applications, including Google Chrome, when capturing mouse events. For both mouse and touch events the same callback is used:

[StructLayout(LayoutKind.Sequential)]
public struct MSLLHOOKSTRUCT
{
    public POINT pt;
    public int mouseData;
    public int flags;
    public int time;
    public UIntPtr dwExtraInfo;
}

...more code...

if (wParam == WM.MOUSEMOVE)
{
    var info = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
    var extraInfo = (uint)info.dwExtraInfo;
    if ((extraInfo & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH)
    {// Touch Move
        Console.WriteLine("Touch move");
    } else
    {
        Console.WriteLine("Mouse move");
    }
}

This means, that first a WM.MOUSEMOVE (=WM_MOUSEMOVE) event must occur. Then, the code identifies touch/mouse events by looking at info.dwExtraInfo.

  1. This observation is similar to question (1) and could imply that Google Chrome has its own touch hook and does not call subsequent callbacks (maybe for security reasons?). Can someone verify this?

  2. Ultimately I am interested in capturing all touch events, independent of the application in the foreground. Does someone know a more reliable approach?

Sabotage answered 18/5, 2018 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.