Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using Fedora 17 LXDE with kernel 3.6.10 and am trying to read raw mouse relative movements from /dev/input/mouseX and/or /dev/input/eventX.

I get data showing mouse clicks (mouse up, mouse down) and rel_* events but all the relative movement data have identical rel_x and rel_y values. i.e., if I move the mouse left, I get rel_x = rel_y = +1. If I move the mouse to the right, I get rel_x = rel_y = +1. Same values when moving the mouse up/down. The values are not always = +1, sometimes they are +2.

Any ideas?

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <istream>
#include <unistd.h>
#include <linux/input.h>

#define MOUSEFILE "/dev/input/event2"

int main()
{
int fd;
struct input_event ie;

if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
    perror("opening device");
    exit(EXIT_FAILURE);
}

while(read(fd, &ie, sizeof(struct input_event))) {
    unsigned char *ptr = (unsigned char*)&ie;
    for(int i=0; i<sizeof(ie); i++)
        printf("%02X ", *ptr++);
    printf("\n");
}

return 0;
}

Typical output:

29 EB F7 50 00 00 00 00 27 6A 0C 00 00 00 00 00 02 00 01 00 01 00 00 00 
29 EB F7 50 00 00 00 00 33 6A 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 
29 EB F7 50 00 00 00 00 F5 90 0C 00 00 00 00 00 02 00 00 00 01 00 00 00 
29 EB F7 50 00 00 00 00 F6 90 0C 00 00 00 00 00 02 00 01 00 01 00 00 00 
29 EB F7 50 00 00 00 00 00 91 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 
29 EB F7 50 00 00 00 00 BF B7 0C 00 00 00 00 00 02 00 00 00 02 00 00 00 
29 EB F7 50 00 00 00 00 C0 B7 0C 00 00 00 00 00 02 00 01 00 02 00 00 00 
29 EB F7 50 00 00 00 00 CA B7 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 
29 EB F7 50 00 00 00 00 1C D7 0C 00 00 00 00 00 02 00 00 00 01 00 00 00 
29 EB F7 50 00 00 00 00 1D D7 0C 00 00 00 00 00 02 00 01 00 01 00 00 00 
29 EB F7 50 00 00 00 00 24 D7 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 
29 EB F7 50 00 00 00 00 F0 3F 0D 00 00 00 00 00 02 00 00 00 01 00 00 00 
29 EB F7 50 00 00 00 00 F1 3F 0D 00 00 00 00 00 02 00 01 00 01 00 00 00 
29 EB F7 50 00 00 00 00 FA 3F 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 
29 EB F7 50 00 00 00 00 51 6A 0D 00 00 00 00 00 02 00 00 00 03 00 00 00 
29 EB F7 50 00 00 00 00 52 6A 0D 00 00 00 00 00 02 00 01 00 03 00 00 00 
29 EB F7 50 00 00 00 00 5A 6A 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 

and some output when clicking a button
72 EE F7 50 00 00 00 00 10 DF 00 00 00 00 00 00 01 00 10 01 01 00 00 00 
72 EE F7 50 00 00 00 00 13 DF 00 00 00 00 00 00 02 00 00 00 01 00 00 00 
72 EE F7 50 00 00 00 00 13 DF 00 00 00 00 00 00 02 00 01 00 01 00 00 00 
72 EE F7 50 00 00 00 00 2B DF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
72 EE F7 50 00 00 00 00 C0 AE 02 00 00 00 00 00 01 00 10 01 00 00 00 00 
72 EE F7 50 00 00 00 00 C5 AE 02 00 00 00 00 00 02 00 00 00 01 00 00 00 
72 EE F7 50 00 00 00 00 C6 AE 02 00 00 00 00 00 02 00 01 00 01 00 00 00 
72 EE F7 50 00 00 00 00 E0 AE 02 00 00 00 00 00 00 00 00 00 00 00 00 00 
share|improve this question
1  
The code looks like...? –  Ignacio Vazquez-Abrams Jan 17 '13 at 16:55
    
I find if I boot to a text mode, it works as expected. I get +1 if moving one direction and -1 (ffff) when moving the other. So, is it a problem with LXDE? –  user30463 Jan 17 '13 at 20:31

2 Answers 2

X is presumably grabbing some kind of exclusive access to the mouse. Reading from it will consume the events, and I doubt that is what you want. I don't know if there is some X-specific API to get the data you want, but my best bet would be checking for something like that. OTOH, it looks like a possible security vulnerability that shouln't be allowed (think a virtual keyboard for entering passwords so they can't be intercepted at the keyboard...).

What are you trying to accomplish? It seems you are looking for a way to implement a solution to a problem, but without knowing the problem we can't suggest better alternatives.

share|improve this answer
    
Just wanting to use the mouse as a robot sensor on a Raspberry Pi eventually. I find the code works as expected in Debian LXDE but not Fedora. It's just easier to do some development/testing on a laptop. –  user30463 Jan 30 '13 at 20:42
    
Finally tracked it down. Seems to be a problem with 50-vmmouse.conf in /usr/share/X11/xorg.conf.d. This driver is loaded in Fedora 17 LXDE but not in Debian Squeeze LXDE. Delete this and the code runs as expected. –  user30463 Jan 31 '13 at 15:11
up vote 0 down vote accepted

Finally tracked it down. Seems to be a problem with 50-vmmouse.conf in /usr/share/X11/xorg.conf.d. This driver is loaded in Fedora 17 LXDE but not in Debian Squeeze LXDE. Delete this and the code runs as expected.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.