-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse.c
More file actions
90 lines (79 loc) · 2.63 KB
/
mouse.c
File metadata and controls
90 lines (79 loc) · 2.63 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
#include<stdio.h>
#include<linux/input.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include "mouse.h"
int count;
int posY;
int posX;
int connect_mouse(char * file){
int fd = open(file, O_RDWR);
if(fd<1){
printf("Error: Please check your input\n");
return -1;
}
posX = 0;
posY = 0;
set_coord_mouse(fd,-10000,-10000);
return fd;
}
void add_set_mouse(int fd, int x, int y){
struct input_event eventx,eventy, event_end;
memset(&eventx, 0, sizeof(eventx));//Reserve memory for event_x
memset(&eventy, 0, sizeof(eventy));//Reserve memory for event_y
memset(&event_end, 0, sizeof(event_end));//Reserve memory for event_end
eventx.type = EV_REL;//set the type of the eventx to relative.
eventx.code = REL_X;//tell the code of eventx to relative value of x.
eventx.value = x;
write(fd, &eventx, sizeof(eventx));
eventy.type = EV_REL;//set the type of the eventx to relative.
eventy.code = REL_Y;//tell the code of eventx to relative value of y.
eventy.value = y;
write(fd, &eventy, sizeof(eventy));
event_end.type = EV_SYN;
event_end.code = SYN_REPORT;
event_end.value = 0;
write(fd, &event_end, sizeof(event_end));
}
void set_coord_mouse(int fd, int x, int y){
if(count >= 1){
int newX,newY = 0;
newX = x - posX;
newY = y - posY;
struct input_event eventx,eventy, event_end;
memset(&eventx, 0, sizeof(eventx));//Reserve memory for event_x
memset(&eventy, 0, sizeof(eventy));//Reserve memory for event_y
memset(&event_end, 0, sizeof(event_end));//Reserve memory for event_end
eventx.type = EV_REL;//set the type of the eventx to relative.
eventx.code = REL_X;//tell the code of eventx to relative value of x.
eventx.value = newX;
write(fd, &eventx, sizeof(eventx));
eventy.type = EV_REL;//set the type of the eventx to relative.
eventy.code = REL_Y;//tell the code of eventx to relative value of y.
eventy.value = newY;
write(fd, &eventy, sizeof(eventy));
event_end.type = EV_SYN;
event_end.code = SYN_REPORT;
event_end.value = 0;
write(fd, &event_end, sizeof(event_end));
if(x != -10000){ //avoid initialisation
posX = x;
posY = y;
count = 0;
}}else{count++;}
}/*
int main()
{
int fd = connect_mouse("/dev/input/event12");
printf("Connection souris OK!!\n");
int x = 50;
printf("entrez une coord en X? \n");
//scanf("%d \n",&x);
printf("déplacement de %d \n", x);
set_coord_mouse(fd,x,0);
printf("fin de déplacement \n");
// scanf("%d \n",&x);
close(fd);
return 0;
}*/