-
Notifications
You must be signed in to change notification settings - Fork 7
/
t2.c
94 lines (75 loc) · 1.74 KB
/
t2.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
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
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>
#define MOUSEFILE "/dev/input/mouse0"
#define UMBRAL 5
int main()
{
int fd;
struct input_event ie;
unsigned char button,bLeft,bMiddle,bRight;
char x,y;
int absolute_x,absolute_y;
if((fd = open(MOUSEFILE, O_RDONLY | O_NONBLOCK)) == -1) {
printf("Device open ERROR\n");
exit(EXIT_FAILURE);
}
else
{
printf("Device open OK\n");
}
int ret, xp=0, yp=0;
printf("right-click to set absolute x,y coordinates origin (0,0)\n");
int ptr = 0;
while (1)
{
ret=read(fd, &ie, sizeof(struct input_event));
if (ret!=-1) {
unsigned char *ptr = (unsigned char*)&ie;
int i;
button=ptr[0];
bLeft = button & 0x1;
bMiddle = ( button & 0x4 ) > 0;
bRight = ( button & 0x2 ) > 0;
x=(char) ptr[1];y=(char) ptr[2];
/*
if (x>0) printf("X DERECHA");
else if(x<0) printf("X IZQUIERDA");
else printf(" X NADA");
if (y>0) printf("y ARRIBA");
else if(y<0) printf("y ABAJO");
else printf(" y NADA");
*/
if (x>0) xp++;
else if(x<0) xp--;
if (y>0) yp--;
else if(y<0) yp++;
if (xp==UMBRAL) {
xp=0;
printf("x DERECHA");
} else if (xp==-UMBRAL) {
xp=0;
printf("x IZQUIERDA");
}
if (yp==UMBRAL) {
yp=0;
printf("x ARRIBA");
} else if (yp==-UMBRAL) {
yp=0;
printf("x ABAJO");
}
//printf("bLEFT:%d, bMIDDLE: %d, bRIGHT: %d, rx: %d ry=%d\n",bLeft,bMiddle,bRight, x,y);
absolute_x+=x;
absolute_y-=y;
if (bRight==1)
{
absolute_x=0;
absolute_y=0;
printf("Absolute x,y coords origin recorded\n");
}
printf("\n");
}
}
return 0;
}