-
Notifications
You must be signed in to change notification settings - Fork 23
/
mouse.c
40 lines (34 loc) · 833 Bytes
/
mouse.c
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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
int fd, bytes;
unsigned char data[3];
const char *pDevice = "/dev/input/mice";
//const char *pDevice = "/dev/input/mouse0";
// Open Mouse
fd = open(pDevice, O_RDWR);
if(fd == -1)
{
printf("ERROR Opening %s\n", pDevice);
return -1;
}
int left, middle, right;
signed char x, y;
while(1)
{
// Read Mouse
bytes = read(fd, data, sizeof(data));
if(bytes > 0)
{
left = data[0] & 0x1;
right = data[0] & 0x2;
middle = data[0] & 0x4;
x = data[1];
y = data[2];
printf("x=%d, y=%d, left=%d, middle=%d, right=%d\n", x, y, left, middle, right);
}
}
return 0;
}