Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- int main(int argc, char *argv[]) {
- char *input_dev = (argc > 1) ? argv[1] : "/dev/input/mouse0";
- int fd;
- uint8_t mouse_inp[3];
- int x = 0, y = 0;
- if ((fd = open(input_dev, O_RDONLY)) == -1) {
- perror("open");
- return -1;
- }
- while (read(fd, mouse_inp, sizeof(mouse_inp))) {
- if (mouse_inp[0] & 0x1) {
- x = 0;
- y = 0;
- }
- else {
- x += (int8_t)mouse_inp[1];
- y += (int8_t)mouse_inp[2];
- }
- printf("x = %+d\ty = %+d\n", x, y);
- fflush(stdout);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement