/dev/input/目錄
/dev/input/目錄下的事件都是在驅(qū)動(dòng)中調(diào)用input_register_device(struct input_dev *dev)產(chǎn)生的。筆者的/dev/input/目錄中的文件如下:
$ ls /dev/input/
by-id by-path event0 event1 event10 event11 event12 event13 event2 event3 event4 event5 event6 event7 event8 event9 mice mouse0 mouse1 mouse2
$ ls -l /dev/input
總用量 0
drwxr-xr-x 2 root root 100 11月 7 11:09 by-id
drwxr-xr-x 2 root root 200 11月 7 11:09 by-path
crw-rw---- 1 root input 13, 64 11月 2 15:53 event0
crw-rw---- 1 root input 13, 65 11月 2 15:53 event1
crw-rw---- 1 root input 13, 74 11月 2 15:53 event10
crw-rw---- 1 root input 13, 75 11月 2 15:53 event11
crw-rw---- 1 root input 13, 76 11月 2 15:53 event12
crw-rw---- 1 root input 13, 77 11月 2 15:53 event13
crw-rw---- 1 root input 13, 66 11月 2 15:53 event2
crw-rw---- 1 root input 13, 67 11月 2 15:53 event3
crw-rw---- 1 root input 13, 68 11月 2 15:53 event4
crw-rw---- 1 root input 13, 69 11月 7 11:09 event5
crw-rw---- 1 root input 13, 70 11月 2 15:53 event6
crw-rw---- 1 root input 13, 71 11月 2 15:53 event7
crw-rw---- 1 root input 13, 72 11月 2 15:53 event8
crw-rw---- 1 root input 13, 73 11月 2 15:53 event9
crw-rw---- 1 root input 13, 63 11月 2 15:53 mice
crw-rw---- 1 root input 13, 32 11月 2 15:53 mouse0
crw-rw---- 1 root input 13, 33 11月 2 15:53 mouse1
crw-rw---- 1 root input 13, 34 11月 7 11:09 mouse2
每個(gè)event代表一個(gè)事件。那么如何知道每個(gè)事件分別與哪個(gè)設(shè)備對(duì)應(yīng)?這需要借助于/proc/bus了。
/proc/bus/input/devices
/proc/bus/input/devices存放了與event對(duì)應(yīng)的相關(guān)設(shè)備信息。筆者電腦中的內(nèi)容如下:
$ cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0005 Version=0000
N: Name="Lid Switch"
P: Phys=PNP0C0D/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:1a/PNP0C0D:00/input/input0
U: Uniq=
H: Handlers=event0
B: PROP=0
B: EV=21
B: SW=1
I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=PNP0C0C/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input1
U: Uniq=
H: Handlers=kbd event1
B: PROP=0
B: EV=3
B: KEY=10000000000000 0
I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input2
U: Uniq=
H: Handlers=sysrq kbd event2 leds
B: PROP=0
B: EV=120013
B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="Ideapad extra buttons"
P: Phys=ideapad/input0
S: Sysfs=/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/VPC2004:00/input/input7
U: Uniq=
H: Handlers=rfkill kbd event6
B: PROP=0
B: EV=13
B: KEY=81000800100c03 4400000000300000 0 2
B: MSC=10
I: Bus=0018 Vendor=06cb Product=ce2d Version=0100
N: Name="MSFT0001:01 06CB:CE2D Mouse"
P: Phys=i2c-MSFT0001:01
S: Sysfs=/devices/pci0000:00/0000:00:15.0/i2c_designware.0/i2c-1/i2c-MSFT0001:01/0018:06CB:CE2D.0001/input/input8
U: Uniq=
H: Handlers=mouse0 event3
B: PROP=0
B: EV=17
B: KEY=30000 0 0 0 0
B: REL=3
B: MSC=10
I: Bus=0018 Vendor=06cb Product=ce2d Version=0100
N: Name="MSFT0001:01 06CB:CE2D Touchpad"
P: Phys=i2c-MSFT0001:01
S: Sysfs=/devices/pci0000:00/0000:00:15.0/i2c_designware.0/i2c-1/i2c-MSFT0001:01/0018:06CB:CE2D.0001/input/input9
U: Uniq=
H: Handlers=mouse1 event4
B: PROP=5
B: EV=1b
B: KEY=e520 10000 0 0 0 0
B: ABS=2e0800000000003
B: MSC=20
I: Bus=0003 Vendor=13d3 Product=56ff Version=1919
N: Name="Integrated Camera: Integrated C"
P: Phys=usb-0000:00:14.0-7/button
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-7/3-7:1.0/input/input11
U: Uniq=
H: Handlers=kbd event7
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0
I: Bus=0019 Vendor=0000 Product=0006 Version=0000
N: Name="Video Bus"
P: Phys=LNXVIDEO/video/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/LNXVIDEO:00/input/input12
U: Uniq=
H: Handlers=kbd event8
B: PROP=0
B: EV=3
B: KEY=3e000b00000000 0 0 0
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sof-hda-dsp Headset Mic"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0/input13
U: Uniq=
H: Handlers=event9
B: PROP=0
B: EV=21
B: SW=10
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sof-hda-dsp Headphone"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0/input14
U: Uniq=
H: Handlers=event10
B: PROP=0
B: EV=21
B: SW=4
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sof-hda-dsp HDMI/DP,pcm=3"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0/input15
U: Uniq=
H: Handlers=event11
B: PROP=0
B: EV=21
B: SW=140
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sof-hda-dsp HDMI/DP,pcm=4"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0/input16
U: Uniq=
H: Handlers=event12
B: PROP=0
B: EV=21
B: SW=140
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sof-hda-dsp HDMI/DP,pcm=5"
P: Phys=ALSA
S: Sysfs=/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0/input17
U: Uniq=
H: Handlers=event13
B: PROP=0
B: EV=21
B: SW=140
I: Bus=0003 Vendor=093a Product=2521 Version=0111
N: Name="USB OPTICAL MOUSE"
P: Phys=usb-0000:00:14.0-5/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-5/3-5:1.0/0003:093A:2521.0005/input/input20
U: Uniq=
H: Handlers=mouse2 event5
B: PROP=0
B: EV=17
B: KEY=1f0000 0 0 0 0
B: REL=1943
B: MSC=10
可以看到,每一項(xiàng)的“H:”一行后邊的內(nèi)容中就是對(duì)應(yīng)的event。以觸摸板為例:
I: Bus=0018 Vendor=06cb Product=ce2d Version=0100
N: Name="MSFT0001:01 06CB:CE2D Touchpad"
P: Phys=i2c-MSFT0001:01
S: Sysfs=/devices/pci0000:00/0000:00:15.0/i2c_designware.0/i2c-1/i2c-MSFT0001:01/0018:06CB:CE2D.0001/input/input9
U: Uniq=
H: Handlers=mouse1 event4
B: PROP=5
B: EV=1b
B: KEY=e520 10000 0 0 0 0
B: ABS=2e0800000000003
B: MSC=20
通過“N:”一行后邊的內(nèi)容可以看出是Touchpad設(shè)備,它對(duì)應(yīng)的事件見于“H: Handlers=mouse1 event4”一行,是event4。
由此引出來一個(gè)常用的輸入事件測(cè)試工具 —— evtest。
evtest
在開發(fā)input子系統(tǒng)驅(qū)動(dòng)時(shí),常常會(huì)使用evtest工具進(jìn)行測(cè)試。evtest是打印evdev內(nèi)核事件的工具,它直接從內(nèi)核設(shè)備讀取并打印設(shè)備描述的帶有值和符號(hào)名的事件,可以用來調(diào)試鼠標(biāo)、鍵盤、觸摸板等輸入設(shè)備
evtest通常用于在X.org中調(diào)試輸入設(shè)備的問題,evtest提供了內(nèi)核的處理信息。根據(jù)這些信息,可以判斷是內(nèi)核問題還是X.org問題。
輸出數(shù)據(jù)中,“type”是input類型,可以是“EV KEY”、“EV SW”、“EV SND”、“EV LED”或數(shù)值;“value”可以是十進(jìn)制也可以是十六進(jìn)制,或者是查詢的kev/開關(guān)/聲音/LED的常量名。
下邊看一下具體的安裝使用方法。
安裝
sudo apt install evtest -y
編譯安裝
$ tar -xjvf evtest_1.33.orig.tar.bz2
$ cd evtest-1.33/
$ ./configure
$ make
$ sudo make install
使用
sudo evtest /dev/input/eventx(x為事件編號(hào))
?注:需要用root用戶,或者sudo操作。
在筆者電腦中,運(yùn)行示例如下:
$ sudo evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: Lid Switch
/dev/input/event1: Power Button
/dev/input/event2: AT Translated Set 2 keyboard
/dev/input/event3: MSFT0001:01 06CB:CE2D Mouse
/dev/input/event4: MSFT0001:01 06CB:CE2D Touchpad
/dev/input/event5: USB OPTICAL MOUSE
/dev/input/event6: Ideapad extra buttons
/dev/input/event7: Integrated Camera: Integrated C
/dev/input/event8: Video Bus
/dev/input/event9: sof-hda-dsp Headset Mic
/dev/input/event10: sof-hda-dsp Headphone
/dev/input/event11: sof-hda-dsp HDMI/DP,pcm=3
/dev/input/event12: sof-hda-dsp HDMI/DP,pcm=4
/dev/input/event13: sof-hda-dsp HDMI/DP,pcm=5
Select the device event number [0-13]:
仍然以Touchpad為例,對(duì)應(yīng)的event為4,輸入4,并隨便在觸摸板上滑動(dòng),結(jié)果如下:文章來源:http://www.zghlxwxcb.cn/news/detail-615744.html
Select the device event number [0-13]: 4
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x6cb product 0xce2d version 0x100
Input device name: "MSFT0001:01 06CB:CE2D Touchpad"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 272 (BTN_LEFT)
Event code 325 (BTN_TOOL_FINGER)
Event code 328 (BTN_TOOL_QUINTTAP)
Event code 330 (BTN_TOUCH)
Event code 333 (BTN_TOOL_DOUBLETAP)
Event code 334 (BTN_TOOL_TRIPLETAP)
Event code 335 (BTN_TOOL_QUADTAP)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 994
Min 0
Max 1224
Resolution 12
Event code 1 (ABS_Y)
Value 505
Min 0
Max 804
Resolution 12
Event code 47 (ABS_MT_SLOT)
Value 0
Min 0
Max 4
Event code 53 (ABS_MT_POSITION_X)
Value 0
Min 0
Max 1224
Resolution 12
Event code 54 (ABS_MT_POSITION_Y)
Value 0
Min 0
Max 804
Resolution 12
Event code 55 (ABS_MT_TOOL_TYPE)
Value 0
Min 0
Max 2
Event code 57 (ABS_MT_TRACKING_ID)
Value 0
Min 0
Max 65535
Event type 4 (EV_MSC)
Event code 5 (MSC_TIMESTAMP)
Properties:
Property type 0 (INPUT_PROP_POINTER)
Property type 2 (INPUT_PROP_BUTTONPAD)
Testing ... (interrupt to exit)
Event: time 1667899054.177672, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 1515
Event: time 1667899054.177672, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 376
Event: time 1667899054.177672, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 382
Event: time 1667899054.177672, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1667899054.177672, type 1 (EV_KEY), code 325 (BTN_TOOL_FINGER), value 1
直接讀取/dev/input/eventx
使用cat查看輸入事件的內(nèi)容,操作相應(yīng)輸入設(shè)備,事件會(huì)上報(bào)內(nèi)容。以字符串方式解讀會(huì)呈現(xiàn)亂碼。如下所示:文章來源地址http://www.zghlxwxcb.cn/news/detail-615744.html
sudo cat /dev/input/event4
b"jcW. 9?b"jcW. 5$b"jcW. 6?b"jcW. Jb"jcW. Eb"jcW. $b"jcW. ?b"jcW. b"jcW. b"jc?6 X"jc?6 b"jc?S Rb"jc?S b"jc?n ??b"jc?n b"jco? ?b"jco? b"jc? 5'b"jc? 6?b"jc? 'b"jc? ?b"jc? h?b"jc? b"jcU? 5+b"jcU? 6?b"jcU? +b"jcU? ?b"jcU? ??b"jcU? b"jci? 5/b"jci? 6?b"jci? /b"jci? ?b"jci? ?b"jci? b"jc?? 54b"jc?? 6?b"jc?? 4b"jc?? ?b"jc?? pb"jc?? b"jc?
58b"jc?
6?b"jc?
8b"jc?
?b"jc?
到了這里,關(guān)于Linux下查看輸入設(shè)備、獲取輸入事件的詳細(xì)方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!