私はカーネル3.6.10でFedora 17 LXDEを使用しており、ネイティブ/dev/input/mouseX
マウスの相対移動から読みたいと思います/dev/input/eventX
。
マウスクリック(マウスの上、マウスの下)とイベントを表示するデータを取得しましたが、すべての相対移動データの合計値rel_*
は同じです。つまり、マウスを左に動かすとなります。マウスを右に動かすと、マウスを上下に動かすのと同じ値が得られます。この値は常に = +1 ではなく、時には +2 です。rel_x
rel_y
rel_x = rel_y = +1
rel_x = rel_y = +1
どんなアイデアがありますか?
#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、これは許可されてはいけないセキュリティの脆弱性のようです(キーボードで傍受されないようにパスワードを入力する仮想キーボードを考えてみてください...)。
何を達成したいですか?あなたは問題に対する解決策を実装する方法を探しているようですが、問題を理解しない限り、より良い選択肢を提案することはできません。