Search code examples
c++winapisendinput

Tracking mouse input events


Currently using SendInput(MOUSEEVENTF_MOVE) to simulate mouse movements. SendInput adds a new mouse event to the thread input queue before being processed.

Is it possible to track/check if an specific event has actually been processed?

Tracking WM_MOUSEMOVE in WndProc is no option since it is possible for the user to issue non-simulated mouse movements at the same time.


Solution

  • Is it possible to track/check if an specific event has actually been processed?

    In general: No.

    SendInput adds a new mouse event to the thread input queue before being processed.

    Well, no. SendInput places input events into the hardware input queue, where they get picked up by the raw input thread, and dispatched to the respective threads' input queues.

    Tracking WM_MOUSEMOVE in WndProc is no option since it is possible for the user to issue non-simulated mouse movements at the same time.

    Correct. You can, however, install a low-level mouse hook, where you can identify injected input1. Injected input has one of the LLMHF_INJECTED or LLMHF_LOWER_IL_INJECTED flags set in the MSLLHOOKSTRUCT structure's flags member.

    A brittle solution that allows you to identify injected input in your application's window procedure's mouse message handlers is to pass a specific dwExtraInfo value through the MOUSEINPUT structure. This value can be queried in the message handler by calling GetMessageExtraInfo. It is unreliable, though, because the system uses those values, too. There is no range of values an application can use, that is guaranteed to not collide with values used by the system.


    1 The low-level mouse hook runs, after input events are dequeued from the hardware input queue. The events have not been processed by applications or even placed into the respective threads' input queues at that point.