[DllImport("user32")]
public static extern int SetCursorPos(int x, int y);
The next API simulates mouse events (left/right click down/up, wheel EXE)
private const int MOUSEEVENTF_MOVE = 0x0001; /* mouse move */
private const int MOUSEEVENTF_LEFTDOWN = 0x0002; /* left button down */
private const int MOUSEEVENTF_LEFTUP = 0x0004; /* left button up */
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008; /* right button down */
DllImport("user32.dll",
CharSet = CharSet.Auto,CallingConvention=CallingConvention.S tdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons,
int dwExtraInfo);
To simulate one click, you need to use this method twice: the first time for down click and the second time for up click. On the save side, wait 100 milliseconds between moving new location and the click, like in the following code:
SetCursorPos(action.X, action.Y)
Thread.Sleep(100);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);