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);