-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.cpp
More file actions
110 lines (86 loc) · 2.49 KB
/
mouse.cpp
File metadata and controls
110 lines (86 loc) · 2.49 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "mouse.h"
QString Mouse::tmpActFile = "";
Mouse::Mouse() {
}
Mouse::~Mouse() {
}
void Mouse::trackMousePosition(int interval) {
// this function will be running in its own thread
forever {
// check if the thread needs to be interrupted
if (QThread::currentThread()->isInterruptionRequested()) {
return;
}
mousePosition = QCursor::pos();
qDebug() << mousePosition;
QThread::sleep(interval);
}
}
LRESULT Mouse::MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
// detect mouse action and record it
PKBDLLHOOKSTRUCT k = (PKBDLLHOOKSTRUCT)(lParam);
POINT p;
mouseAction temp;
bool write = false;
// qDebug() << "lParam ... " << lParam;
switch (wParam) {
// case (WM_MOUSEMOVE) : {
// GetCursorPos(&p);
//// qDebug() << "Mouse moved ... " << p.x << "\t" << p.y;
// break;
// }
case (WM_RBUTTONDOWN) : {
GetCursorPos(&p);
qDebug() << wParam << "\tRight button DOWN at " << p.x << "\t" << p.y;
temp.action = (uint16_t)WM_RBUTTONDOWN;
temp.time = QDateTime::currentMSecsSinceEpoch();
write = true;
break;
}
case (WM_RBUTTONUP) : {
GetCursorPos(&p);
qDebug() << wParam << "\tRight button UP at " << p.x << "\t" << p.y;
temp.action = (uint16_t)WM_RBUTTONUP;
temp.time = QDateTime::currentMSecsSinceEpoch();
write = true;
break;
}
case (WM_LBUTTONDOWN) : {
GetCursorPos(&p);
qDebug() << wParam << "\tLeft button DOWN at " << p.x << "\t" << p.y;
temp.action = (uint16_t)WM_LBUTTONDOWN;
temp.time = QDateTime::currentMSecsSinceEpoch();
write = true;
break;
}
case (WM_LBUTTONUP) : {
GetCursorPos(&p);
qDebug() << wParam << "\tLeft button UP at " << p.x << "\t" << p.y;
temp.action = (uint16_t)WM_LBUTTONUP;
temp.time = QDateTime::currentMSecsSinceEpoch();
write = true;
break;
}
}
temp.pos = QPoint(p.x, p.y);
// only write if something useful was taken
if (write) {
if (tmpActFile.isEmpty()) {
qDebug() << "NO TEMP FILE FOR ACTIONS WAS DEFINED";
} else {
ofstream toTemp(Mouse::tmpActFile.toStdString().c_str(), ios::app);
if (toTemp.is_open()) {
toTemp << temp.time << "\t" << temp.action << "\t" << temp.pos.x() << "\t" << temp.pos.y();
toTemp << "\n";
toTemp.close();
}
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
QPoint Mouse::getMousePosition() {
return mousePosition;
}
void Mouse::setMousePosition(QPoint pos) {
QCursor::setPos(pos);
}