-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clicker.cs
48 lines (41 loc) · 1.32 KB
/
Clicker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace fastclick
{
/**
Most code by Nasreddine
https://stackoverflow.com/questions/8272681/how-can-i-simulate-a-mouse-click-at-a-certain-position-on-the-screen#8273118
*/
class Clicker
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("user32.dll")]
private static extern bool GetCursorPos(out POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
private struct POINT
{
public int X;
public int Y;
}
private static POINT GetCursorPosition()
{
POINT lpPoint;
GetCursorPos(out lpPoint);
return lpPoint;
}
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
//This simulates a left mouse click
public static void LeftMouseClick()
{
POINT p = GetCursorPosition();
mouse_event(MOUSEEVENTF_LEFTDOWN, p.X, p.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, p.X, p.Y, 0, 0);
}
}
}