解释/proc/bus/input/devices数据中的EV

Gab*_*iel 14 linux devices proc events

谁能向我解释一下EVin的价值/proc/bus/input/devices是什么?

键盘总是有价值的120013。为什么?

Run*_*ium 27

它代表bitmask设备支持的事件。

devicesAT 键盘输入示例:

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 
B: PROP=0
B: EV=120013
B: KEY=20000 200 20 0 0 0 0 500f 2100002 3803078 f900d401 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7
Run Code Online (Sandbox Code Playgroud)

B前面的代表bitmapNPSUH在相应的名字值只是第一个字母,IID以有序的方式:

  • I => @id: id of the device (struct input_id)
    • Bus     => id.bustype
    • Vendor  => id.vendor
    • Product => id.product
    • Version => id.version
  • N => name of the device.
  • P => physical path to the device in the system hierarchy.
  • S => sysfs path.
  • U => unique identification code for the device (if device has it).
  • H => list of input handles associated with the device.
  • B => bitmaps
    • PROP => device properties and quirks.
    • EV   => types of events supported by the device.
    • KEY  => keys/buttons this device has.
    • MSC  => miscellaneous events supported by the device.
    • LED  => leds present on the device.

位掩码

如您所知,计算机以二进制形式处理,因此:

1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
...
Run Code Online (Sandbox Code Playgroud)

因此,如果我有一个位图,其值5可以保存位 0 和 2,换句话说,可以为每个数字命名并检查它们是否对应于一个值。

例如

A = 1,  001
B = 2,  010
C = 4,  100
Run Code Online (Sandbox Code Playgroud)

那么,如果我MYVAR = 5101二进制,这将检查:

MYVAR & A == TRUE   (101 & 001 => 001)
MYVAR & B == FALSE  (101 & 010 => 000)
MYVAR & C == TRUE   (101 & 100 => 100 )
Run Code Online (Sandbox Code Playgroud)

因此我的 varA 和 C。


内核使用更复杂/更复杂的方式,并按偏移量设置位。一个原因是使用了一台计算机 (CPU) 整数中可用的更多位。例如查看KEY位图。

所以,如果我们说:

A = 0
B = 1
C = 6
...
Run Code Online (Sandbox Code Playgroud)

进而

target = 0;
set_bit(A, target);  => target ==      0001
set_bit(C, target);  => target == 0100 0001
Run Code Online (Sandbox Code Playgroud)

解码 120013

该值为120013十六进制。作为二进制它给了我们:

0x120013 == 0001 0010 0000 0000 0001 0011 binary
               1    2    0    0    1    3
Run Code Online (Sandbox Code Playgroud)

从右数依次为:

   2            1               <= offset (10's)
3210 9876 5432 1098 7654 3210   <= offset (counted from right)
0001 0010 0000 0000 0001 0011   <= binary

Set bits are:
   0, 1, 4, 17, 20
Run Code Online (Sandbox Code Playgroud)

然后检查input-event-codes.h你发现它们对应于:

   0  EV_SYN (0x00)
   1  EV_KEY (0x01)
   4  EV_MSC (0x04)
  17  EV_LED (0x11)
  20  EV_REP (0x14)
Run Code Online (Sandbox Code Playgroud)

为了检查它们的含义,内核文档提供了一个快速介绍。

* EV_SYN:
  - Used as markers to separate events. Events may be separated in time or in
    space, such as with the multitouch protocol.

* EV_KEY:
  - Used to describe state changes of keyboards, buttons, or other key-like
    devices.

* EV_MSC:
  - Used to describe miscellaneous input data that do not fit into other types.

* EV_LED:
  - Used to turn LEDs on devices on and off.

* EV_REP:
  - Used for autorepeating devices.
Run Code Online (Sandbox Code Playgroud)

这个“EDIT 2 (continued):”可能特别有趣。

  • 这个答案太神奇了! (2认同)