Skip to content

Instantly share code, notes, and snippets.

@msadowski
Created July 24, 2016 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msadowski/06b6245949ca38ca1dbe47aed81db834 to your computer and use it in GitHub Desktop.
Save msadowski/06b6245949ca38ca1dbe47aed81db834 to your computer and use it in GitHub Desktop.
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BejeweledBot
{
class VirtualMouse
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint 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;
private Cursor Cursor;
public VirtualMouse()
{
this.Cursor = new Cursor(Cursor.Current.Handle);
}
public void Move(int X, int Y)
{
Cursor.Position = new Point(X, Y);
}
public void Click()
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment