Normally I wouldn't bump, but since this is probably a common question I decided to post anyway.
Code:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
namespace Eradicator
{
public static class Mouse
{
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
public static void Click(MouseButton button, int x, int y)
{
Cursor.Position = new Point(x, y);
mouse_event((int)button, x, y, 0, 0);
}
}
[Flags]
public enum MouseButton : int
{
LeftDown = 0x02,
LeftUp = 0x04,
RightDown = 0x08,
RightUp = 0x10,
LeftClick = LeftDown | LeftUp,
RightClick = RightDown | RightUp,
}
}
Then using it, this would click button1.
Code:
Point p = this.PointToScreen(Point.Empty);
Mouse.Click(MouseButton.LeftClick, p.X + button1.Left + 5, p.Y + button1.Top + 5);