Android下event事件深度解析

来源:互联网 发布:不喜欢知否的男主 编辑:程序博客网 时间:2024/06/02 18:46


Android手机下getevent/sendevent,源代码路径system/core/toolbox/下,sendevent.c getevent.c getevent.h

getevent

使用getevent获得/dev/input/eventX设备汇报的事件,这个命令还会输出所有event设备的基本信息,

add device 1: /dev/input/event2
  name:     "qpnp_pon"
add device 2: /dev/input/event0
  name:     "sensorprocessor"
could not get driver version for /dev/input/mice, Not a typewriter
add device 3: /dev/input/event5
  name:     "gpio-keys"
add device 4: /dev/input/event4
  name:     "msm8994-florida-snd-card Headset Jack"
add device 5: /dev/input/event3
  name:     "msm8994-florida-snd-card Button Jack"
add device 6: /dev/input/event1
  name:     "synaptics_dsx_i2c"

其中如上对应关系

device 6: /dev/input/event1:"synaptics_dsx_i2c" ===》显示屏touchscreen

device 3: /dev/input/event5:"gpio-keys"              ===》键盘keypad

device 1: /dev/input/event2: "qpnp_pon"            ===》按键pwrkey


Android可以使用sendevent来模拟触屏,键盘以及其他类型的event事件,

sendevent /dev/input/eventX type code value

/dev/input/eventX 对应一个event设备,可以通过getevent获得可用的event设备

type, code, value的定义可参看kernel/include/linux/input.h和kernel/include/uapi/input.h


input

 /dev/input目录下的事件都是在驱动中调用input_register_device(struct input_dev *dev)产生的。

root@:/dev/input # ll
ll
crw-rw---- root     input     13,  64 1970-01-15 11:37 event0
crw-rw---- root     input     13,  65 1970-01-15 11:37 event1
crw-rw---- root     input     13,  66 1970-01-15 11:37 event2
crw-rw---- root     input     13,  67 1970-01-15 11:37 event3
crw-rw---- root     input     13,  68 1970-01-15 11:37 event4
crw-rw---- root     input     13,  69 1970-01-15 11:37 event5
crw-rw---- root     input     13,  63 1970-01-15 11:37 mice

与event对应的相关设备信息位于/proc/bus/input/devices,

root@:/ # cd proc/bus/input/devices
cd proc/bus/input/devices
/system/bin/sh: cd: /proc/bus/input/devices: Not a directory
2|root@kinzie_uds:/ # cat proc/bus/input/devices
cat proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="sensorprocessor"
P: Phys=
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=alsa_to_h2w switch_to_motosh event0 cpufreq keychord
B: PROP=0
B: EV=23
B: KEY=100000 0 10000000000000 0
B: SW=1


I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="synaptics_dsx_i2c"
P: Phys=synaptics_dsx_i2c/input0
S: Sysfs=/devices/soc.0/f9924000.i2c/i2c-2/2-0020/input/input1
U: Uniq=
H: Handlers=kgsl event1 cpufreq
B: PROP=2
B: EV=9
B: ABS=661800000000000


I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="qpnp_pon"
P: Phys=qpnp_pon/input0
S: Sysfs=/devices/virtual/input/input2
U: Uniq=
H: Handlers=event2 cpufreq keychord
B: PROP=10
B: EV=3
B: KEY=14000000000000 0


I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="msm8994-florida-snd-card Button Jack"
P: Phys=ALSA
S: Sysfs=/devices/soc.0/fe034000.sound/sound/card0/input3
U: Uniq=
H: Handlers=event3 cpufreq keychord
B: PROP=0
B: EV=3
B: KEY=40 0 0 0 0 8e 400000000 0 c000000000000 0


I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="msm8994-florida-snd-card Headset Jack"
P: Phys=ALSA
S: Sysfs=/devices/soc.0/fe034000.sound/sound/card0/input4
U: Uniq=
H: Handlers=alsa_to_h2w switch_to_motosh event4
B: PROP=0
B: EV=21
B: SW=10054


I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="gpio-keys"
P: Phys=gpio-keys/input0
S: Sysfs=/devices/soc.0/gpio_keys.83/input/input5
U: Uniq=
H: Handlers=event5 cpufreq keychord
B: PROP=0
B: EV=3
B: KEY=8000000000000 0

0 0