using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
namespace mouse_clicker
{
public partial class Form1 : Form
{
delegate void mouse();
int ms;
int savedx, savedy, errorx = 0, errory = 0;
enum mef : uint
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010,
WHEEL = 0x00000800,
XDOWN = 0x00000080,
XUP = 0x00000100
}
public Form1()
{
InitializeComponent();
timer_helper.Start();
}
#region mouse
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
[DllImport("user32.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
int dwExtraInfo);
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
struct POINT
{
public int x;
public int y;
}
void Middown()
{
mouse_event((uint)mef.LEFTDOWN, 0, 0, 0, 0);
}
void Midup()
{
mouse_event((uint)mef.LEFTUP, 0, 0, 0, 0);
}
void Mousedu()
{
Middown();
Midup();
}
#endregion
private void xToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void timer_helper_Tick(object sender, EventArgs e)
{
int x = GetAsyncKeyState(Keys.F8);
if ((x == 1) || (x == Int16.MinValue))
{
ms = Convert.ToInt32(textBox1.Text);
try
{
timer_cooldown.Interval = ms;
}
catch (Exception)
{
MessageBox.Show("Not Valid number, interval has been set to 2000ms.");
textBox1.Text = "2000";
timer_cooldown.Interval = 2000;
}
timer_cooldown.Start();
pictureBox1.Image = Properties.Resources.green_light;
POINT position;
GetCursorPos(out position);
savedx = position.x;
savedy = position.y;
label5.Text = savedx.ToString() + ", " + savedy.ToString();
}
x = GetAsyncKeyState(Keys.F9);
if ((x == 1) || (x == Int16.MinValue))
{
timer_cooldown.Stop();
pictureBox1.Image = Properties.Resources.css_images_red_light;
}
x = GetAsyncKeyState(Keys.F10);
if ((x == 1) || (x == Int16.MinValue))
{
POINT position;
GetCursorPos(out position);
errorx = position.x;
errory = position.y;
label7.Text = errorx.ToString() + ", " + errory.ToString();
}
}
private void timer_cooldown_Tick(object sender, EventArgs e)
{
SetCursorPos(savedx, savedy);
Thread.Sleep(100);
mouse ms = new mouse(Mousedu);
ms();
if (errorx != 0)
{
SetCursorPos(errorx, errory);
Thread.Sleep(100);
ms();
}
}
}
}
