Last active
August 29, 2015 13:57
-
-
Save evonsdesigns/9521767 to your computer and use it in GitHub Desktop.
A C# tool for programmaticly moving the mouse and left/right clicking.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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