-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.c
executable file
·60 lines (41 loc) · 1018 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "mouse.h"
// Abre o mouse e retorna o file descriptor
int openMouse() {
// Abre o mouse
int fd;
if ((fd = open(MousePath, O_RDWR)) == -1) {
printf("Houve um erro abrindo %s... você executou como superusuário?\n", MousePath);
return -1;
}
return fd;
}
// Retorna 1 se botao esquerdo apertado, 0 senao
int esquerdoApertado(int mouse) {
int bytes;
int esquerdo;
unsigned char data[3];
bytes = read(mouse, data, sizeof(data));
// Verifica se o botao esquerdo foi apertado
esquerdo = data[0] & 0x1;
if(esquerdo){
return 1;
}
return 0;
}
// Retorna um vetor signed char [2] com as coordenadas x e y do mouse
signed char* coordenadasMouse(int mouse) {
signed char x, y;
int bytes;
unsigned char data[3];
bytes = read(mouse, data, sizeof(data));
x = data[1];
y = data[2];
signed char* coord = (signed char*) malloc(2*sizeof(signed char));
coord[0] = x;
coord[1] = y;
return coord;
}