Linux環境でのアプリケーションプログラミング(8):入力システム

1つ:入力システム

入力システムの紹介とドライバーリファレンス:https//blog.csdn.net/qq_34968572/article/details/89875957

入力システムイベントの読み取りと分析:

1.イベントに関連するデバイス情報の説明を取得します。

cat /proc/bus/input/devices

パラメータの対応する意味:

I:デバイスID

struct input_id {
	__u16 bustype; //总线类型
	__u16 vendor;  //与厂商相关的ID
	__u16 product; //与产品相关的ID
	__u16 version; //版本号
};

N:デバイス名

P:システム階層内のデバイスの物理パス

S:sysファイルシステムにあるパス

U:デバイスの一意の識別コード

H:デバイスに関連付けられている入力ハンドルのリスト

B:ビットマップ

PROP:设备属性。
EV:设备支持的事件类型。
KEY:此设备具有的键/按钮。
MSC:设备支持的其他事件。
LED:设备上的指示灯。

2.イベントコマンドを表示します。

hexdump /dev/input/event1

最初にカーネルのイベントイベントタイプ構造を確認し、次にhexdumpコマンドに従ってマウスイベントを分析します。

struct timeval {
	__kernel_time_t		tv_sec;		/* seconds */
	__kernel_suseconds_t	tv_usec;	/* microseconds */
};

struct input_event {
	struct timeval time;
	__u16 type;
	__u16 code;
	__s32 value;
};

列1:hexdumpシリアル番号

2〜3列:秒

4〜5列目:微妙

6列:イベントタイプ、相対イベント、絶対イベントなど。

/*
 * Event types
 */

#define EV_SYN			0x00  同步事件
#define EV_KEY			0x01  按键事件
#define EV_REL			0x02  相对事件
#define EV_ABS			0x03  绝对事件
#define EV_MSC			0x04
#define EV_SW			0x05
#define EV_LED			0x11
#define EV_SND			0x12
#define EV_REP			0x14
#define EV_FF			0x15
#define EV_PWR			0x16
#define EV_FF_STATUS		0x17
#define EV_MAX			0x1f
#define EV_CNT			(EV_MAX+1)

列7:イベント値。マウスなどの相対イベントの場合、コードはマウスの現在の位置を基準にしたx座標またはy座標を表します。

/*
 * Keys and buttons
 *
 * Most of the keys/buttons are modeled after USB HUT 1.12
 * (see http://www.usb.org/developers/hidpage).
 * Abbreviations in the comments:
 * AC - Application Control
 * AL - Application Launch Button
 * SC - System Control
 */

#define KEY_RESERVED		0
#define KEY_ESC			1
#define KEY_1			2
#define KEY_2			3
#define KEY_3			4
#define KEY_4			5
... ...

列8:特定のデバイスの対応する値の意味。現在の位置に対するオフセットとして表されます。

2:アプリケーション

struct input_event event_mouse ;
int fd    = -1 ;

fd = open("/dev/input/event2", O_RDONLY);
read(fd, &event_mouse, sizeof(event_mouse));
if(EV_ABS == event_mouse.type || EV_REL == event_mouse.type)
{
//code表示相对位移X或者Y,当判断是X时,打印X的相对位移value
//当判断是Y时,打印Y的相对位移value
if(event_mouse.code == REL_X)
{
    printf("event_mouse.code_X:%d\n", event_mouse.code);
    printf("event_mouse.value_X:%d\n", event_mouse.value);
}
else if(event_mouse.code == REL_Y)
{
    printf("event_mouse.code_Y:%d\n", event_mouse.code);
    printf("event_mouse.value_Y:%d\n", event_mouse.value);
}

 

おすすめ

転載: blog.csdn.net/qq_34968572/article/details/107403611