设备节点:
dev 字符设备节点:
shell@android:/dev/input $ ll
crw-rw---- root input 13, 64 2013-11-28 17:23 event0
crw-rw---- root input 13, 65 2013-11-28 17:23 event1
crw-rw---- root input 13, 66 2013-11-28 17:23 event2
crw-rw---- root input 13, 67 2013-11-28 17:23 event3
crw-rw---- root input 13, 68 2013-11-28 17:23 event4
crw-rw---- root input 13, 69 2013-11-28 17:23 event5
crw-rw---- root input 13, 70 2013-11-29 10:31 event6
crw-rw---- root input 13, 63 2013-11-28 17:23 mice
shell@android:/dev/input $
sys 设备节点:
shell@android:/sys/class/input $ ll
lrwxrwxrwx root root 2013-11-29 11:08 event0 -> ../../devices/platform/mtk-kpd/input/input0/event0
lrwxrwxrwx root root 2013-11-29 11:08 event1 -> ../../devices/virtual/input/input1/event1
lrwxrwxrwx root root 2013-11-29 11:08 event2 -> ../../devices/virtual/input/input2/event2
lrwxrwxrwx root root 2013-11-29 11:08 event3 -> ../../devices/virtual/input/input3/event3
lrwxrwxrwx root root 2013-11-29 11:08 event4 -> ../../devices/virtual/input/input4/event4
lrwxrwxrwx root root 2013-11-29 11:08 event5 -> ../../devices/virtual/input/input5/event5
lrwxrwxrwx root root 2013-11-29 11:08 event6 -> ../../devices/virtual/input/input6/event6
lrwxrwxrwx root root 2013-11-29 11:08 input0 -> ../../devices/platform/mtk-kpd/input/input0
lrwxrwxrwx root root 2013-11-29 11:08 input1 -> ../../devices/virtual/input/input1
lrwxrwxrwx root root 2013-11-29 11:08 input2 -> ../../devices/virtual/input/input2
lrwxrwxrwx root root 2013-11-28 17:23 input3 -> ../../devices/virtual/input/input3
lrwxrwxrwx root root 2013-11-28 17:23 input4 -> ../../devices/virtual/input/input4
lrwxrwxrwx root root 2013-11-28 17:23 input5 -> ../../devices/virtual/input/input5
lrwxrwxrwx root root 2013-11-29 11:08 input6 -> ../../devices/virtual/input/input6
lrwxrwxrwx root root 2013-11-29 11:08 mice -> ../../devices/virtual/input/mice
shell@android:/sys/class/input $
getevent :
执行adb shell getevent 可以查看到有几个input 设备、input event号及设备名的对应关系等信息:
liaohs@liaohs-11-04:~$ adb shell getevent
add device 1: /dev/input/event6
name: "AVRCP"
add device 2: /dev/input/event0
name: "mtk-kpd"
add device 3: /dev/input/event5
name: "mtk-tpd-kpd"
add device 4: /dev/input/event4
name: "mtk-tpd"
add device 5: /dev/input/event3
name: "LEV_KPD"
add device 6: /dev/input/event2
name: "hwmdata"
add device 7: /dev/input/event1
name: "ACCDET"
根据我测试getevent是有用的,如下通过getevent获取event0的Power key事件:
adb shell getevent /dev/input/event0
0001 0074 00000001
0000 0000 00000000
0001 0074 00000000
0000 0000 00000000
获取到的event type code value参考/kernel/include/linux/input.h
linux key code : input-event-codes.h
把getevent获取事件用sendevent无效,我失败的测试方法如下:
adb shell sendevent /dev/input/event0 0001 0074 00000001
adb shell sendevent /dev/input/event0 0000 0000 00000000
adb shell sendevent /dev/input/event0 0001 0074 00000000
adb shell sendevent /dev/input/event0 0000 0000 00000000
必须 将event事件转换成十进制,才能发送成功,如下 :
adb shell sendevent /dev/input/event0 1 116 1
adb shell sendevent /dev/input/event0 0 0 0
see more : python+adb实现物理按键长按(比如长按关机)
https://www.cnblogs.com/xmmc/p/11022526.html
getevent -l 参数 :
130|shell@android:/ $ getevent -l dev/input/event4
EV_ABS ABS_MT_TOUCH_MAJOR 00000001 //touch 事件的起始
EV_ABS ABS_MT_POSITION_X 00000233 // touch x 座标
EV_ABS ABS_MT_POSITION_Y 000001bb // touch y 座标
EV_ABS 003c 00000040 // touch 面积/压力
EV_ABS 003d 00000040 // touch 面积/压力
EV_ABS ABS_MT_TRACKING_ID 00000000 // touch第几个手指
EV_SYN SYN_MT_REPORT 00000000 //touch第几个手指的事件
EV_SYN SYN_REPORT 00000000 //touch 一次事件的结事同步
EV_ABS ABS_MT_TOUCH_MAJOR 00000001
EV_ABS ABS_MT_POSITION_X 0000022f
EV_ABS ABS_MT_POSITION_Y 000001bb
EV_ABS 003c 00000040
EV_ABS 003d 00000040
EV_ABS ABS_MT_TRACKING_ID 00000000
EV_SYN SYN_MT_REPORT 00000000
EV_SYN SYN_REPORT 00000000
EV_ABS ABS_MT_TOUCH_MAJOR 00000001
EV_ABS ABS_MT_POSITION_X 0000022c
EV_ABS ABS_MT_POSITION_Y 000001bc
EV_ABS 003c 00000041
EV_ABS 003d 00000041
EV_ABS ABS_MT_TRACKING_ID 00000000
EV_SYN SYN_MT_REPORT 00000000
EV_SYN SYN_REPORT 00000000
root@S939:/ # getevent -l dev/input/event0
EV_KEY KEY_POWER DOWN //power key 按下事件
EV_SYN SYN_REPORT 00000000 //事件同步
EV_KEY KEY_POWER UP
EV_SYN SYN_REPORT 00000000
EV_KEY KEY_VOLUMEDOWN DOWN
EV_SYN SYN_REPORT 00000000
EV_KEY KEY_VOLUMEDOWN UP
EV_SYN SYN_REPORT 00000000
sendevent、 input keyevent 使用:
send event无法使用,可以用input command代替
shell@xx:/ $ whence input
/system/bin/input
shell@xx:/ $ input
Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad
The commands and default sources are:
text <string> (Default: touchscreen) 输入文本
keyevent [--longpress] <key code number or name> ... (Default: keyboard) 模拟按键
tap <x> <y> (Default: touchscreen) 模拟点击
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) 模拟滑动
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
模拟按键: input keyevent 25(模拟按下键值为25的按键)
输入文本: input text ssss(输入文本为ssss)
模拟滑动: input swipe 100 300 700 1000 2000(从坐标为(100,300)到(700,1000)进行滑动,时长为2000ms)
模拟点击: input tap 200 300(模拟点击坐标为(200,300)的点)
input keyevent xxx:
其中xxx 代表Key code,参考:/frameworks/base/core/java/android/view/KeyEvent.java
下面是input keyevent几个比较常用的用法:
input keyevent 3 // Home
input keyevent 4 // Back
input keyevent 19 //Up
input keyevent 20 //Down
input keyevent 21 //Left
input keyevent 22 //Right
input keyevent 23 //Select/Ok
input keyevent 24 //Volume+
input keyevent 25 // Volume-
input keyevent 82 // Menu 菜单
input keyevent 7 // 数字0
input keyevent 8 // 数字1
input keyevent 26 // Power key
input keyevent 27 // Camera
dev设备接口使用参考纹编程代码:
bootable/recovery/minui/events.c
参考:
http://blog.csdn.net/kickxxx/article/details/7482392
http://blog.csdn.net/learnrose/article/details/6236890
http://blog.csdn.net/lichaoandy/article/details/6565893