Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <linux/input.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- int cleanSTDIN()
- {
- while (getchar()!='\n');
- return 1;
- }
- long getInteger(char* msg, long from, long till)
- {
- int count = 0;
- long m = 0;
- char c;
- do
- {
- printf("\n");
- printf(msg);
- } while (((scanf("%d%c", &m, &c)!=2 || c!='\n') && cleanSTDIN()) || m<from || m>till);
- return m;
- }
- long randomTill(long max)
- {
- unsigned long
- numBin = (unsigned long) max + 1,
- numRand = (unsigned long) RAND_MAX + 1,
- binSize = numRand / numBin,
- defect = numRand % binSize;
- long z;
- while (numRand - defect <= (unsigned long)(z = random()));
- return z/binSize;
- }
- int main()
- {
- struct input_event event, event_end;
- int fd = open("/dev/input/event4", O_RDWR);
- long ma = getInteger("Enter max amplitude [points, 0..50]: ", 0, 50);
- long ta = getInteger("Enter max wait time [usecs , 0..200000]: ", 0, 200000);
- if (fd < 0)
- {
- printf("Mouse access attempt failed:%s\n", strerror(errno));
- return -1;
- }
- memset(&event, 0, sizeof(event));
- memset(&event, 0, sizeof(event_end));
- gettimeofday(&event.time, NULL);
- event.type = EV_REL;
- gettimeofday(&event_end.time, NULL);
- event_end.type = EV_SYN;
- event_end.code = SYN_REPORT;
- event_end.value = 0;
- while(1)
- {
- event.code = rand() % 2 ? REL_X : REL_Y;
- event.value = (rand() % 2 ? -1 : 1)*randomTill(ma);
- write(fd, &event, sizeof(event));
- write(fd, &event_end, sizeof(event_end));
- usleep(randomTill(ta));
- }
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement