Created
September 11, 2017 13:24
-
-
Save xspager/687841677dcf2a2c010711af9b72cbaf to your computer and use it in GitHub Desktop.
simple test for linux input mouse with relative position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/input.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
int main(int argc, char **argv) | |
{ | |
int fd, i; | |
int x=0,y=0,z=0; | |
if(argc < 2) { | |
printf("usage: %s /dev/input/eventX \n", argv[0]); | |
return 1; | |
} | |
fd = open(argv[1], O_RDONLY); | |
struct input_event ev[64]; | |
while (1) | |
{ | |
int bytes = read(fd, &ev, sizeof(struct input_event)*64); | |
if(bytes > 0){ | |
for (i = 0; i < (int)(bytes / sizeof(struct input_event)); i++) { | |
if(ev[i].type == 1) | |
//printf("key %i state %i\n", ev.code, ev.value); | |
if(ev[i].value == 0) | |
printf(" : [key %i]\n ", ev[i].code); | |
if(ev[i].type == EV_REL) { | |
//printf("Ev.type %d, Ev.code %d, Ev.value %d\n", ev[i].type, ev[i].code, ev[i].value); | |
if(ev[i].code == REL_X){ | |
x+=ev[i].value; | |
} | |
if(ev[i].code == REL_Y){ | |
y+=ev[i].value; | |
} | |
if(ev[i].code == REL_WHEEL) | |
z+=ev[i].value; | |
printf("X = %d, Y = %d, Z = %d\n", x,y,z); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment