Skip to content

Instantly share code, notes, and snippets.

@evonsdesigns
Last active August 29, 2015 13:57
Show Gist options
  • Save evonsdesigns/9521767 to your computer and use it in GitHub Desktop.
Save evonsdesigns/9521767 to your computer and use it in GitHub Desktop.
A C# tool for programmaticly moving the mouse and left/right clicking.
public class MouseController
{
[DllImport("User32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public static void DoMouseClick()
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, new UIntPtr());
}
public static void DoRightMouseClick()
{
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, new UIntPtr());
}
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
public static void MoveCursorToPoint(int x, int y)
{
SetCursorPos(x, y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment