I'm working with a mouse USB driver and I really don't know how to differenciate and use information send by /dev/input/mouse0
and /dev/input/mice
After few searches on Google, I found this code about using /dev/input/mice
int fd, bytes;
unsigned char data[4];
const char *pDevice = "/dev/input/mice";
// Open Mouse
fd = open(pDevice, O_RDWR);
if(fd == -1)
{
printf("ERROR Opening %s\n", pDevice);
return -1;
}
int left, middle, right;
signed char x, y;
// 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);
if(left)
return left;
if(right)
return right;
if(middle)
return middle;
}
return 0;
This program works but didn't get any information about the wheel scroll.
I was able to find a program which uses /dev/input/event0
int fd;
struct input_event ev
const char* pFile = "/dev/input/event0";
fd = open(pFile, O_RDONLY);
if(fd == -1)
{
printf("ERROR Opening %s\n", pFile);are
return -1;
}
read(fd, &ev, sizeof(ev));
std::cout << "type : " << ev.type << " code : " << ev.code << " value : " << ev.value << std::endl;
close(fd);
return 0;
But there is a problem for diagonal movement because this file saved only 1 coordinate at the same time, and the X coordinate has priority over the Y, so it's pretty annoying when you want to move your mouse on Y axis.
I didn't find any code to use /dev/input/mouse0
, so what information is saved in this file?
My questions are:
- What information is saved in
/dev/input/mouse0
? - How can I read all mouse information without opening 2 files and without a priority problem (wheel scrolling + X/Y axis movement)?
cat /dev/input/mice
, there is nothing printed in the terminal when I use the scroll wheel/dev/input/mouse0
too, probably I must use/dev/input/event0
and try to fix my code about the priority of X axis than Y axis