-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.cpp
More file actions
135 lines (102 loc) · 3.47 KB
/
mouse.cpp
File metadata and controls
135 lines (102 loc) · 3.47 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Datastructs
#include <set>
#include <csignal> // for ctrl-c
#include <iostream> // cout <<
#include <cstdio> // printf & scan etc
// file operations
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <linux/input-event-codes.h>
#include <sys/time.h>
void print_event_details(struct input_event *data ) {
std::cout << "\tcode: " << std::hex << data->code << std::endl
<< "\tval:" << std::dec << data->value << std::endl;
}
std::set<int> keys = std::set<int>();
std::set<int> unhandeld_events;
int fp = 0;
void sigint_handeler(int signal) {
try {
close(fp);
std::cout << "keys found\r\n";
for (int i : keys ) {
std::cout << i << std::endl;
}
std::cout << std::endl << std::endl
<< "unhandeld events: " << std::endl;
for (int i : unhandeld_events ) {
std::cout << i << std::endl;
}
} catch (int er) {}
exit(0);
}
int main(int argc, char **argv) {
int fp = open("/dev/input/event8", O_RDONLY);
if (!fp) {
std::cerr << "could not open input";
return 1;
}
int is_ok = EXIT_SUCCESS;
//void * buff = malloc(sizeof(struct input_event));
signal(SIGINT, sigint_handeler);
while (is_ok != EXIT_FAILURE) {
char buff[sizeof(struct input_event)];
int err = read(fp, buff, sizeof(struct input_event));
if (err == -1) {
std::puts("I/O error when reading");
break;
}
struct input_event *incoming = (struct input_event *) buff;
if (incoming->type == EV_REL ) {
continue;
}
std::cout << "time: " << incoming->time.tv_sec << std::endl;
switch (incoming->type) {
case EV_KEY:
std::cout << "EV_KEY:" << incoming->value << std::endl;
print_event_details(incoming);
keys.insert(incoming->code);
// 272
// 325
// 330
// 333
// 334
case EV_SW:
// binary values... okay fair
break;
break;
case EV_REL:
// i currently only use absolute.
case EV_SYN:
// NAH.
break;
case EV_ABS:
std::cout << "EV_ABS:\r\n";
switch (incoming->code) {
case ABS_X:
std::cout << " move x by " << incoming->value << std::endl;
break;
case ABS_Y:
std::cout << " move Y by " << incoming->value << std::endl;
break;
case ABS_MT_POSITION_X:
std::cout << " center x is " << incoming->value << std::endl;
break;
case ABS_MT_POSITION_Y:
std::cout << " center y is " << incoming->value << std::endl;
break;
default:
std::cout << " code: " << std::hex << incoming->code << std::endl << " val: " << std::dec << incoming->value << std::endl;
break;
}
break;
default:
unhandeld_events.insert(incoming->code);
break;
}
std::cout << std::endl;
}
sigint_handeler(0);
return is_ok;
}