今天在维护公司的一个小项目的时候,发现按公司手机的某个物理按键,**相应的Service后,会在屏幕上模拟的点击了屏幕的某个坐标点。好家伙,原来是之前该项目的版本是按这个物理按键后,会弹出一个对话框,提示用户需要打开某些服务,然后出于良好的用户体验,直接模拟点击事件,点击该对话框,不让用户做多余的操作。
但是后期版本的改动,该功能不需要了,但是代码可能没有改动完全,因此出现了上述bug。查看代码发现,原来是执行了下面的代码才模拟出在屏幕上的点击事件。
- Runtime.getRuntime().exec("input tap " + mPositiveButtonX + " " + mPositiveButtonY);
修复此bug,就是将上述代码处注释掉即可。
===============================================================
通过这段代码,我去百度了input事件的相关资料。
首先在在cmd窗口敲命令:adb shell input help,得到相关的input事件的用法
- C:\Documents and Settings\Administrator>adb shell input help
- Error: Unknown command: help
- 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后可以跟很多参数, text相当于输入内容,keyevent相当于手机物理或是屏幕按键,tap相当于touch事件,swipe相当于滑动。下面我们来学习相应的用法。
1、input text用法
- C:\Documents and Settings\Administrator>adb shell
- [email protected]_66t_l1:/ $ input text OuyangPeng
如果你此时鼠标是在一个可以输入文本的文本框之类的控件上,那么将在该文本框上输入出 OuyangPeng 字符串。如下图所示:
2、 input keyevent用法
先列举 input keyevent 几个比较常用的code值:
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 菜单
下面来测试一下:
- [email protected]_66t_l1:/ $ input keyevent 3
- [email protected]_66t_l1:/ $ input keyevent 24
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
上面是进行音量的减小,执行了几次之后,音量减小到了中间位置。此时会弹出音量加减界面,如下所示。
3、input tab用法
首先进入到下面界面如下所示:
然后通过input tap命令模拟触摸屏幕,代码如下。
- [email protected]_66t_l1:/ $ input tap 600 800
4、input swipe用法
input swipe模拟的是滑动事件,input swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen),需要将起始的坐标传进去。如下面代码,将会向左滑动
- [email protected]_66t_l1:/ $ input swipe 600 800 300 800
- [email protected]_66t_l1:/ $ input swipe 300 800 600 800
0 --> "KEYCODE_UNKNOWN"
1 --> "KEYCODE_MENU"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "TAG_LAST_KEYCODE"
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================
今天在维护公司的一个小项目的时候,发现按公司手机的某个物理按键,**相应的Service后,会在屏幕上模拟的点击了屏幕的某个坐标点。好家伙,原来是之前该项目的版本是按这个物理按键后,会弹出一个对话框,提示用户需要打开某些服务,然后出于良好的用户体验,直接模拟点击事件,点击该对话框,不让用户做多余的操作。
但是后期版本的改动,该功能不需要了,但是代码可能没有改动完全,因此出现了上述bug。查看代码发现,原来是执行了下面的代码才模拟出在屏幕上的点击事件。
- Runtime.getRuntime().exec("input tap " + mPositiveButtonX + " " + mPositiveButtonY);
修复此bug,就是将上述代码处注释掉即可。
===============================================================
通过这段代码,我去百度了input事件的相关资料。
首先在在cmd窗口敲命令:adb shell input help,得到相关的input事件的用法
- C:\Documents and Settings\Administrator>adb shell input help
- Error: Unknown command: help
- 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后可以跟很多参数, text相当于输入内容,keyevent相当于手机物理或是屏幕按键,tap相当于touch事件,swipe相当于滑动。下面我们来学习相应的用法。
1、input text用法
- C:\Documents and Settings\Administrator>adb shell
- [email protected]_66t_l1:/ $ input text OuyangPeng
如果你此时鼠标是在一个可以输入文本的文本框之类的控件上,那么将在该文本框上输入出 OuyangPeng 字符串。如下图所示:
2、 input keyevent用法
先列举 input keyevent 几个比较常用的code值:
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 菜单
下面来测试一下:
- [email protected]_66t_l1:/ $ input keyevent 3
- [email protected]_66t_l1:/ $ input keyevent 24
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
- [email protected]_66t_l1:/ $ input keyevent 25
上面是进行音量的减小,执行了几次之后,音量减小到了中间位置。此时会弹出音量加减界面,如下所示。
3、input tab用法
首先进入到下面界面如下所示:
然后通过input tap命令模拟触摸屏幕,代码如下。
- [email protected]_66t_l1:/ $ input tap 600 800
4、input swipe用法
input swipe模拟的是滑动事件,input swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen),需要将起始的坐标传进去。如下面代码,将会向左滑动
- [email protected]_66t_l1:/ $ input swipe 600 800 300 800
- [email protected]_66t_l1:/ $ input swipe 300 800 600 800
0 --> "KEYCODE_UNKNOWN"
1 --> "KEYCODE_MENU"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "TAG_LAST_KEYCODE"
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================