Search code examples
c++winapimouseeventmouseraw-input

To get two mice data the same time by using Raw Input


Raw input could get two mice data, but if two mice are moved by the user simultaneously, it seems I can only get the data of the mouse being detected first and cannot get the movement information of another mouse.

To get the mouse information of different mice, this is what I did:

PeekMessage( &msg, c_handle, WM_INPUT, WM_INPUT, PM_NOREMOVE) != 0

GetRawInputData(    (HRAWINPUT)msg.lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize  )

So, when the first mouse handle is being peeked, the second mouse can only be detected after the operation on the first mouse is stopped.

The msdn talked about using Buffered Read for devices that can produce large amounts of raw input. But this method has many problems itself and should only work for multiple inputs on a single mouse (device)

Not sure how to peek two mouse handles and get two mouse data when they are moved simultaneously.


Solution

  • Perhaps using PM_NOREMOVE is causing an issue. I suggest either using GetMessage() or PM_REMOVE. What you are describing should not be a problem, as I have done something similar and not had this issue.

    Also make sure you are calling DefRawInputProc() at the end of the wndproc message.