-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmouse_w32.hpp
87 lines (77 loc) · 2.03 KB
/
mouse_w32.hpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (C) 2013 George Wong
* GNU General Public License
*
* Notes:
* > In MOUSE::moveTo, it's a bit of a misnomer to use dx and dy as
* they are not true deltas, but that's how the fields are called.
*/
namespace MOUSE {
/* Forward declarations */
int moveTo (size_t x, size_t y);
int position (size_t &x, size_t &y);
int rightClick ();
int rightDown ();
int rightUp ();
int leftClick ();
int leftDown ();
int leftUp ();
/* Move the position of the cursor */
int moveTo (size_t x, size_t y) {
double dx = x * (65535.0f / (::GetSystemMetrics (SM_CXSCREEN)-1));
double dy = y * (65535.0f / (::GetSystemMetrics (SM_CYSCREEN)-1));
INPUT Input = {0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = LONG(dx);
Input.mi.dy = LONG(dy);
::SendInput(1,&Input,sizeof(INPUT));
return 0;
}
/* Return mouse position in pixels (x, y) */
int position (size_t &x, size_t &y) {
POINT cursorPos;
GetCursorPos(&cursorPos);
x = cursorPos.x;
y = cursorPos.y;
return 0;
}
/* Right-button functions */
int rightClick () {
rightDown();
rightUp();
}
int rightDown () {
INPUT Input = {0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
::SendInput(1,&Input,sizeof(INPUT));
return 0;
}
int rightUp () {
INPUT Input = {0};
::ZeroMemory(&Input,sizeof(INPUT));
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
::SendInput(1,&Input,sizeof(INPUT));
return 0;
}
/* Left-button functions */
int leftClick () {
leftDown();
leftUp();
}
int leftDown () {
INPUT Input = {0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
::SendInput(1,&Input,sizeof(INPUT));
}
int leftUp () {
INPUT Input = {0};
::ZeroMemory(&Input,sizeof(INPUT));
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
::SendInput(1,&Input,sizeof(INPUT));
}
}