Parsing WM_INPUT over Remote Desktop

A common problem I’ve had when working at game studios is that game interpreted mouse movement over remote desktop is unreliable. Usually the effect is that any movement of the mouse causes the camera to fly off to an undesired location without any ability to get the camera back to where you would like it. Luckily I’ve been able to track down this problem (twice now) to make working over remote desktop bearable again. Sadly, I’ve always had problems in finding a resource online to solve the problem.

Both problem cases have come up when parsing WM_INPUT. Although I’ve only had two examples so far, I’ve noticed that both seemed to follow this posted example.  For most cases, it seems that the example works as intended but for some reason the values appear as garbage over remote desktop.  The problem is that it is assumed the WM_INPUT message is passing delta coordinate values while it is documented as passing either absolute or delta values.  Of course, parsing these absolute coordinate values as delta results in unexpected behavior when passed to your application.

The solution is, of course, to check for the type of data being sent to you.  That sounds easy enough but I’ve been unable to find documentation stating the coordinate system the absolute values are in.  I’ve tried using ClientToScreen/ScreenToClient but neither seem to do what I expect.  What I have noticed is that the coordinates seem to come through between 0->65535 (although stored in a LONG).  In practice, I’ve used this observation to convert the coordinates after checking if the MOUSE_VIRTUAL_DESKTOP flag was set.

The following is an example code snippit.

Hope that helps! At minimum, I hope the next time I google this problem I can discover my old findings. 🙂

4 thoughts to “Parsing WM_INPUT over Remote Desktop”

  1. Thank you for this! I hadn’t seen absolute coordinates until I used my app over Remote Desktop.

    Though having to handle both cases makes me think it’d be easier to go back to using WM_MOUSEMOVE instead 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *