Android 按键模拟输入事件和Monitor工具的使用

有时候,进行Android开发,会遇到屏幕会失灵的情况,但是显示无问题,这时候可以使用一些工具/手段,在电脑端控制模拟屏幕输入,或者使用adb 相关命令模拟按键事件输入,以达到我们测试/验证的目的。

1.adb命令模拟Back, Home, Menu三个按键

user@swd:/local $ adb shell input keyevent 82  [Menu键]
user@swd:/local $ 
user@swd:/local $ adb shell input keyevent 4    [Back键]
user@swd:/local $ 
user@swd:/local $ adb shell input keyevent 3    [Home键]
user@swd:/local $ 
user@swd:/local $ adb shell input keyevent 26   [Power键]


这个后面的那个数值,可以从Android项目源码或者API文档中查询。

/frameworks/base/core/java/android/view/KeyEvent.java

2.adb monitor远程控制工具

我这便使用的时adb monitor,界面如下,鼠标点击拖拽手机屏幕映射区域即可:

Android 按键模拟输入事件和Monitor工具的使用_第1张图片


工具包中共有两个文件,直接运行test.sh即可远程连接上USB已经连接的手机,以下是连接过程的一些log。

user@swd:/local/sda/adb monitor$ ll
total 332
drwxrwxr-x  2 user user   4096 Apr 11 14:28 ./
drwxr-xr-x 17 user user   4096 Apr 11 14:27 ../
-rw-------  1 user user 326390 Apr 11 14:27 androidscreencast.jar
-rwxrwxrwx  1 user user    112 Apr 11 14:28 test.sh*
user@swd:/local/sda/adb monitor$ 
user@swd:/local/sda/adb monitor$ ./test.sh 
./test.sh: line 2: adb-4.4: command not found
Old client closed
export CLASSPATH=/data/local/tmp/InjectAgent.jar; exec app_process /system/bin net.srcz.android.screencast.client.Main 1324
[agent] Starting ...
[agent] wait Socket
[agent] New client ! Socket[address=/127.0.0.1,port=43774,localPort=1324]
[agent] wait Socket
connect to agent is successful.
succes !
[agent] writer connectOK message.
[agent] Received : pointer/10/10/0/544.0/1851.0/-1
[agent] Received : pointer/10/10/1/544.0/1851.0/-1
[agent] Received : pointer/10/10/0/554.0/1686.0/-1
[agent] Received : pointer/10/10/1/554.0/1686.0/-1
[agent] Received : pointer/10/10/0/569.0/1372.0/-1
[agent] Received : pointer/10/10/2/562.0/1359.0/-1
[agent] Received : pointer/10/10/2/562.0/1352.0/-1

工具获取连接为:

http://download.csdn.net/detail/u013398960/9810667


你可能感兴趣的:(Android,Android,远程控制工具,tools)