How to set the mouse cursor on the X, Y coordinates, left-click and scroll left, right, top, bottom

As described in the header, I tried to find a way to set the coordinates of the mouse using Cursor.Position = new Point(58, 128); Then, while holding the Left Mouse (Down) button, I try to move in a different direction (random direction). For example, if I were to go to Google Earth and set the cursor position to 0,0 , the cursor will then scroll the map. If someone can help, I would certainly appreciate him.

thanks

Solution: floatas, thanks again for the response to this post. I spent yesterday and today trying to figure it out, and finally I got a job. I will post my code in the hope that this will help others.

+5
source share
1 answer

First of all, you will need to import some functions.

To change the cursor position:

  [DllImport("user32.dll", EntryPoint = "SetCursorPos")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetCursorPos( [In] int X, [In] int Y); 

To simulate mouse events:

 [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event( [In] uint dwFlags, [In] uint dx, [In] uint dy, [In] int dwData, [In] uint dwExtraInfo); 

Possible mouse events:

 public enum MouseEvents { MOUSEEVENTF_LEFTDOWN = 0x02, MOUSEEVENTF_LEFTUP = 0x04, MOUSEEVENTF_RIGHTDOWN = 0x08, MOUSEEVENTF_RIGHTUP = 0x10, MOUSEEVENTF_WHEEL = 0x0800, } 

You can send the mouse down and mouse, simulating a click:

 mouse_event((uint)MouseEvents.MOUSEEVENTF_LEFTDOWN | (uint)MouseEvents.MOUSEEVENTF_LEFTUP, X, Y, 0, 0); 

Did not check this, but should click, drag and drop:

 mouse_event((uint)MouseEvents.MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0); SetCursorPos((int)X+10, (int)Y+10); mouse_event((uint)MouseEvents.MOUSEEVENTF_LEFTUP, X+10, Y+10, 0, 0); 
+1
source

All Articles