android怎么模拟点击而不受控制
本文讲的是通过使用代码,可以控制手机的屏幕和物理按键,也就是说不只是在某一个APP里去操作,而是整个手机系统。
更多问题解决办法请参考android学习手册,例子、源码、文档全部搞定,采用androidstudo的目录结构,360手机助手中下载。下面是截图。
getevent/sendevent
getevent&sendevent 是Android系统下的一个工具,可以模拟多种按键和触屏操作,产生的是raw event,raw event经过event hub处理产生最终的gesture事件。getevent用于获取当前系统input设备的一些参数和实时事件的数据;sendevent用于发送input事件,这俩命令的作用就是相当于解放了手,可以通过命令直接调用Linux底层来控制手机,工具的源码位于Android SDK的system/core/toolbox下(sendevent.c getevent.c)。
getevent
用法说明:
[plain] view plain copy print?
#?getevent?-h
Usage:?getevent?[-t]?[-n]?[-s?switchmask]?[-S]?[-v?[mask]]?[-p]?[-q]?[-c?count]?[-r]?[device]
-t:?show?time?stamps
-n:?don't?print?newlines
-s:?print?switch?states?for?given?bits
-S:?print?all?switch?states
-v:?verbosity?mask?(errs=1,?dev=2,?name=4,?info=8,?vers=16,?pos.?events=32)
-p:?show?possible?events?(errs,?dev,?name,?pos.?events)
-q:?quiet?(clear?verbosity?mask)
-c:?print?given?number?of?events?then?exit
-r:?print?rate?events?are?received
# getevent -h
Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-p] [-q] [-c count] [-r] [device]
-t: show time stamps
-n: don't print newlines
-s: print switch states for given bits
-S: print all switch states
-v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32)
-p: show possible events (errs, dev, name, pos. events)
-q: quiet (clear verbosity mask)
-c: print given number of events then exit
-r: print rate events are received
其中?[-t]?参数显示事件的时间戳,[-n]?取消事件显示时的换行符,[-s switchmask]?得到指定位的开关状态,[-S]?得到所有开关的状态,[-v [mask]]?根据mask的值显示相关信息,后面详细介绍mask的使用方法,[-p]?显示每个设备支持的事件类型和编码,[-q]?只显示事件数据,[-c count]?只显示count次事件的数据,[-r]?显示事件接收频率。
[java] view plain copy print?
shell@android:/?$?getevent?-p
shell@android:/ $ getevent -p
[java] view plain copy print?
getevent?-p
add?device?1:?/dev/input/event7
name:?"gpio-keys"
events:
KEY?(0001):?0066
input?props:
<none>
add?device?2:?/dev/input/event2
name:?"alps"
events:
ABS?(0003):?0000:?value?12,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
0001:?value?-4,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
0002:?value?-252,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
000a:?value?0,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
0010:?value?0,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
0011:?value?0,?min?-4096,?max?4096,?fuzz?0,?flat?0,?resolution?0
input?props:
<none>
add?device?3:?/dev/input/event6
name:?"7k_handset"
events:
KEY?(0001):?006b00720073007400e2
input?props:
<none>
add?device?4:?/dev/input/event5
name:?"proximity_sensor"
events:
ABS?(0003):?0019:?value?1,?min?0,?max?1,?fuzz?0,?flat?0,?resolution?0
input?props:
<none>
add?device?5:?/dev/input/event4
name:?"accelerometer_sensor"
events:
input?props:
<none>
add?device?6:?/dev/input/event3
name:?"magnetic_sensor"
events:
input?props:
<none>
add?device?7:?/dev/input/event1
name:?"7x27a_kp"
events:
KEY?(0001):?00720073
input?props:
<none>
add?device?8:?/dev/input/event0
name:?"sec_touchscreen"
events:
KEY?(0001):?0066008b009e00d9
ABS?(0003):?002f:?value?0,?min?0,?max?4,?fuzz?0,?flat?0,?resolution?0
0030:?value?0,?min?0,?max?255,?fuzz?0,?flat?0,?resolution?0
0032:?value?0,?min?0,?max?100,?fuzz?0,?flat?0,?resolution?0
0035:?value?0,?min?0,?max?480,?fuzz?0,?flat?0,?resolution?0
0036:?value?0,?min?0,?max?800,?fuzz?0,?flat?0,?resolution?0
0039:?value?0,?min?0,?max?4,?fuzz?0,?flat?0,?resolution?0
LED?(0011):?0008
input?props:
INPUT_PROP_DIRECT
getevent -p
add device 1: /dev/input/event7
?name: "gpio-keys"
?events:
KEY (0001): 0066
?input props:
<none>
add device 2: /dev/input/event2
?name: "alps"
?events:
ABS (0003): 0000 ?: value 12, min -4096, max 4096, fuzz 0, flat 0, resolution 0
0001 ?: value -4, min -4096, max 4096, fuzz 0, flat 0, resolution 0
0002 ?: value -252, min -4096, max 4096, fuzz 0, flat 0, resolution 0
000a ?: value 0, min -4096, max 4096, fuzz 0, flat 0, resolution 0
0010 ?: value 0, min -4096, max 4096, fuzz 0, flat 0, resolution 0
0011 ?: value 0, min -4096, max 4096, fuzz 0, flat 0, resolution 0
?input props:
<none>
add device 3: /dev/input/event6
?name: "7k_handset"
?events:
KEY (0001): 006b ?0072 ?0073 ?0074 ?00e2
?input props:
<none>
add device 4: /dev/input/event5
?name: "proximity_sensor"
?events:
ABS (0003): 0019 ?: value 1, min 0, max 1, fuzz 0, flat 0, resolution 0
?input props:
<none>
add device 5: /dev/input/event4
?name: "accelerometer_sensor"
?events:
?input props:
<none>
add device 6: /dev/input/event3
?name: "magnetic_sensor"
?events:
?input props:
<none>
add device 7: /dev/input/event1
?name: "7x27a_kp"
?events:
KEY (0001): 0072 ?0073
?input props:
<none>
add device 8: /dev/input/event0
?name: "sec_touchscreen"
?events:
KEY (0001): 0066 ?008b ?009e ?00d9
ABS (0003): 002f ?: value 0, min 0, max 4, fuzz 0, flat 0, resolution 0
0030 ?: value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
0032 ?: value 0, min 0, max 100, fuzz 0, flat 0, resolution 0
0035 ?: value 0, min 0, max 480, fuzz 0, flat 0, resolution 0
0036 ?: value 0, min 0, max 800, fuzz 0, flat 0, resolution 0
0039 ?: value 0, min 0, max 4, fuzz 0, flat 0, resolution 0
LED (0011): 0008
?input props:
INPUT_PROP_DIRECT
可以看到 [-p] 参数显示出来当前系统存在的所有input设备,并且把每个设备支持的事件类型以及编码都列举了出来。
每一个device相当于手机所支持的input设备,每个device里面的events下:KEY(0001) 、ABS(0003)、SYN(0000)等表示该设备所支持的事件类型:EV_SYN?[0000] (同步事件),EV_KEY?[0001] (按键事件),EV_ABS?[0003] (绝对值事件)
举例event0中的KEY类型:
[java] view plain copy print?
KEY?(0001):?0066008b009e00d9
KEY?(0001):?0066008b009e00d9
表示sec_touchscreen支持的按键编码有:KEY_HOME?[0066] (HOME键),KEY_MENU?[008b] (MENU键)
KEY_BACK?[009e] (BACK键),KEY_SEARCH?[00d9] (SEARCH键)
举例event0中的ABS类型: