Reputation: 61
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
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.
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.
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.
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?
Ultimately I am interested in capturing all touch events, independent of the application in the foreground. Does someone know a more reliable approach?
Upvotes: 6
Views: 932