Skip to content

Instantly share code, notes, and snippets.

@melvyniandrag
Created May 16, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvyniandrag/387c077abae1533cfc54792985de6df9 to your computer and use it in GitHub Desktop.
Save melvyniandrag/387c077abae1533cfc54792985de6df9 to your computer and use it in GitHub Desktop.
Read /dev/input/mouse0
#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