-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouse.cs
62 lines (52 loc) · 1.52 KB
/
Mouse.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Runtime.InteropServices;
namespace MHP3rdController
{
static class Mouse
{
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
static extern bool GetCursorPos(out Point lpPoint);
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int X;
public int Y;
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
public Point(System.Drawing.Point pt) : this(pt.X, pt.Y) { }
public static implicit operator System.Drawing.Point(Point p)
{
return new System.Drawing.Point(p.X, p.Y);
}
public static implicit operator Point(System.Drawing.Point p)
{
return new Point(p.X, p.Y);
}
public static Point operator + (Point p1, Point p2)
{
return new Point(p1.X + p2.X, p1.Y + p2.Y);
}
public static Point operator - (Point p1, Point p2)
{
return new Point(p1.X - p2.X, p1.Y - p2.Y);
}
}
public static Point Position
{
get
{
Point pos;
GetCursorPos(out pos);
return pos;
}
set
{
SetCursorPos(value.X, value.Y);
}
}
}
}