-
Notifications
You must be signed in to change notification settings - Fork 0
/
coord.c
executable file
·85 lines (75 loc) · 1.88 KB
/
coord.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
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <linux/input.h>
#include <errno.h>
int main (int argc, char *argv[]){
struct input_event event,event2,event3, event_end;
int sim_fd;
int x,y;
char buffer[10];
int cnt = 1;
int fd,fd2;
int nBytes;
// sysfs
sim_fd = open("/sys/devices/platform/vms/coordinates", O_RDWR);
//sim_fd = open("/sys/devices/platform/virmouse/vmevent", O_RDWR);
/*
fd = open("/dev/input/event3", O_RDWR);
fd2 = open("/dev/input/event2", O_RDWR);
if(fd < 0) {
printf("Error open mouse:%s", strerror(errno));
return -1;
}
*/
if(sim_fd < 0) {
perror("Couldn't open vms coordinate file");
}
memset(&event, 0, sizeof(event));
memset(&event2, 0, sizeof(event2));
//memset(&event3, 0, sizeof(event3));
memset(&event_end, 0, sizeof(event_end));
gettimeofday(&event.time, NULL);
gettimeofday(&event_end.time, NULL);
while(1) {
// generating random coordinate
x = random()%20;
y = random()%20;
if (x%2) x = -x;
if (y%2) y = -y;
sprintf (buffer, "%d %d %d",x,y, 1);
write(sim_fd, buffer, strlen(buffer));
//nBytes = read(fd, &event, sizeof(event));
//printf("%d\n", nBytes);
//write(fd2, &nBytes, sizeof(event));
fsync(sim_fd);
/*
//move coordinate
event.type = EV_REL;
event.code = REL_X;
event.value = x;
event2.type = EV_REL;
event2.code = REL_Y;
event2.value = y;
//event3.type = EV_KEY;
//event3.code = BTN_0;
event_end.type = EV_SYN;
event_end.code = SYN_REPORT;
event_end.value = 100;
write(fd, &event, sizeof(event));
write(fd, &event2, sizeof(event2));
//write(fd, &event3, sizeof(event3));
write(fd, &event_end, sizeof(event_end));
*/
sleep(1);
printf("BJ count : %d, x = %d, y = %d\n",cnt,x,y);
cnt++;
}
//close(fd);
close(sim_fd);
}