-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse.cpp
More file actions
executable file
·47 lines (41 loc) · 809 Bytes
/
Copy pathMouse.cpp
File metadata and controls
executable file
·47 lines (41 loc) · 809 Bytes
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
#include "Mouse.hpp"
#include <stdexcept>
#include <poll.h>
extern "C"
{
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
}
bool MouseEvent::lmb()
{
return data[0] & 0x1;
}
bool MouseEvent::rmb()
{
return data[0] & 0x2;
}
char MouseEvent::xrel()
{
return data[1];
}
char MouseEvent::yrel()
{
return data[2];
}
int fd = open("/dev/input/mice", O_RDONLY);
//int fd = open("/dev/input/event4", O_RDONLY);
bool PollMouseEvent(MouseEvent &e)
{
if(fd < 0)
throw std::runtime_error(std::string("open: ") + strerror(errno));
struct pollfd query = {fd, POLLIN, 0};
if(poll(&query, 1, 0) > 0)
{
if(read(fd, &e, 3) != 3)
throw std::runtime_error(std::string("read: ") + strerror(errno));
return true;
}
return false;
}