Created
May 16, 2018 20:01
-
-
Save melvyniandrag/387c077abae1533cfc54792985de6df9 to your computer and use it in GitHub Desktop.
Read /dev/input/mouse0
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 <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
int main(int argc, char** argv) | |
{ | |
int fd, bytes; | |
unsigned char data[3]; | |
const char *pDevice = "/dev/input/mouse0"; | |
// Open Mouse | |
fd = open(pDevice, O_RDONLY); | |
if(fd == -1) | |
{ | |
printf("ERROR Opening %s\n", pDevice); | |
return -1; | |
} | |
int left, middle, right; | |
signed char x, y; | |
while(1) | |
{ | |
// Read Mouse | |
bytes = read(fd, data, sizeof(data)); | |
if(bytes > 0) | |
{ | |
left = data[0] & 0x1; | |
right = data[0] & 0x2; | |
middle = data[0] & 0x4; | |
x = data[1]; | |
y = data[2]; | |
printf("x=%d, y=%d, left=%d, middle=%d, right=%d\n", x, y, left, middle, right); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment