-3

I am developing a C# application to simulate mouse movement using SendInput declared in Winuser.h. My calls to SendInput work fine and I can move the mouse around the screen.

What I then tried was to record user mouse movement using:

    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(ref POINT lpPoint);

and then pass the mouse points to SendInput. I noticed a discrepancy between the mouse values obtained by GetCursorPos and where SendInput actually positions the mouse. For example, a mouse x position of 1300 (far right of screen) corresponds to the mouse positioning near left of screen using SendInput.

What's the relation between the POINT data obtained via GetCursorPos and the coordinate system used by SendInput.

Thanks.

Lance

Lance
  • 411
  • 2
  • 6
  • 18
  • You neglected to show any code. We've no idea how you call SendInput. Perhaps you get it wrong. We cannot see whether you checked for errors. Perhaps you can show a complete program that demonstrates the problem. – David Heffernan Dec 05 '14 at 17:02
  • No issues with either api call so I didn't bother posting the code. I've since found the solution, GetCursorPos returns screen coordinates and sendinput requires absolute coordinates. This post contains the conversion necessary : http://stackoverflow.com/questions/8021954/sendinput-doesnt-perform-click-mouse-button-unless-i-move-cursor – Lance Dec 05 '14 at 20:55

1 Answers1

2

As discussed in the following question:

SendInput doesn't perform click mouse button unless I move cursor

The screen coordinates returned by GetCursorPos need to be converted to absolute and passed to SendInput:

dx =  (x * 65536) / GetSystemMetrics(SystemMetric.SM_CXSCREEN);
dy = (y * 65536) / GetSystemMetrics(SystemMetric.SM_CYSCREEN);

Lance.

Community
  • 1
  • 1
Lance
  • 411
  • 2
  • 6
  • 18