从 /dev/input/events 读取鼠标时出现问题

从 /dev/input/events 读取鼠标时出现问题

我正在使用带有内核 3.6.10 的 Fedora 17 LXDE,并尝试从/dev/input/mouseX和/或读取原始鼠标相对移动/dev/input/eventX

我获取显示鼠标单击(鼠标向上、鼠标向下)和rel_*事件的数据,但所有相对移动数据都具有相同的rel_xrel_y值。即,如果我向左移动鼠标,我会得到rel_x = rel_y = +1.如果我将鼠标移到右侧,我会得到rel_x = rel_y = +1.向上/向下移动鼠标时的值相同。这些值并不总是 = +1,有时是 +2。

有任何想法吗?

#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;
}

典型输出:

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 

答案1

X 可能正在获取某种对鼠标的独占访问权。从中读取事件会消耗事件,我怀疑这就是您想要的。我不知道是否有一些特定于 X 的 API 可以获取您想要的数据,但我最好的选择是检查类似的内容。 OTOH,这看起来像是一个可能的安全漏洞,不应该被允许(想想一个用于输入密码的虚拟键盘,这样它们就不会在键盘上被拦截......)。

你想达到什么目的?您似乎正在寻找一种方法来实现问题的解决方案,但在不了解问题的情况下,我们无法建议更好的替代方案。

答案2

终于追踪到了。似乎是 /usr/share/X11/xorg.conf.d 中的 50-vmmouse.conf 有问题。该驱动程序在 Fedora 17 LXDE 中加载,但在 Debian Squeeze LXDE 中未加载。删除此代码,代码将按预期运行。

相关内容