1. Send keyboard events:
Command format 1:adb Shell input keyevent "value"
where value and the corresponding key code are listed in the following table:
KeyEvent Value keycode Comment
0 Keycode_unknown
1 keycode_menu command fails in SDK2.1 Simulator, sendevent command is possible
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
Ten Keycode_3
Keycode_4
Keycode_5
Keycode_6
Keycode_7
Keycode_8
Keycode_9
Keycode_star
Keycode_pound
Keycode_dpad_up
Keycode_dpad_down
Keycode_dpad_left
Keycode_dpad_right
Keycode_dpad_center
Keycode_volume_up
Keycode_volume_down
Keycode_power
Keycode_camera
Keycode_clear
Keycode_a
Keycode_b
Keycode_c
Keycode_d
Keycode_e
Keycode_f
Keycode_g
Approx. keycode_h
Panax Notoginseng keycode_i
Keycode_j
Keycode_k
Keycode_l
Keycode_m
Keycode_n
Keycode_o
Keycode_p
Keycode_q
Keycode_r
keycode_s
keycode_t
Keycode_u
Keycode_v
Wuyi Keycode_w
Keycode_x
Keycode_y
Keycode_z
Keycode_comma
Keycode_period
Keycode_alt_left
Keycode_alt_right
Keycode_shift_left
Keycode_shift_right
Keycode_tab
Keycode_space
Keycode_sym
Keycode_explorer
Keycode_envelope
Keycode_enter
Keycode_del
Keycode_grave
Keycode_minus
Keycode_equals
Keycode_left_bracket
Keycode_right_bracket
Keycode_backslash
Keycode_semicolon
Keycode_apostrophe
Keycode_slash
Keycode_at
Keycode_num
Keycode_headsethook
Keycode_focus
Bayi Keycode_plus
Keycode_menu
Keycode_notification
Keycode_search
Tag_last_keycode
Command format 2:adb shell sendevent [device] [type] [code] [value]
For example: adb shell sendevent/dev/input/event0 1 229 1 means press the menu key
ADB Shell Sendevent/dev/input/event0 1 229 0 means Press to release the menu key
Note: The above commands need to be used in combination
Full command:
ADB shell sendevent/dev/input/event4 1 139 1;adb Shell sendevent/dev/input/event4 1 1;adb Shell Sendevent/dev/input /event4 0 0 0;adb Shell sendevent/dev/input/event4 1 139 0;adb Shell sendevent/dev/input/event4 1 0;adb Shell Sendev Ent/dev/input/event4 0 0 0
The number is obtained by manually clicking the menu key according to the ADB shell getevent
The following commands are also known:
Key Name CODE
MENU 229
HOME 102
Back (back button) 158
Call Button 231
End (end call button) 107
2. Send mouse events (Touch):
Command format: adb shell sendevent [device] [type] [code] [value]
Sendevent/dev/input/eventx Type code value
/dev/input/eventx corresponds to an event device that can be getevent to obtain the available event devices
The definition of type, code, value can be see kernel/include/linux/input.h
Scenario 1: Touch on a coordinate point
If you touch the x-coordinate of the screen at a point with a 40,y coordinate of 210, the command is as follows
ADB shell sendevent/dev/input/event0 3 0 40
ADB shell sendevent/dev/input/event0 3 1 210
ADB shell sendevent/dev/input/event0 1 1//touch
ADB shell sendevent/dev/input/event0 0 0 0//it must have
adb shell sendevent/dev/input/event0 1 0//untouch
ADB shell sendevent/dev/input/event0 0 0 0//it must have
Note: The above six sets of commands must be used in conjunction with
Scenario 2: Simulate sliding trajectory (can be downloaded and tested with Apaint software)
The following example shows a horizontal line starting at (100,200) and ending with (108,200) on the Apaint software.
ADB shell sendevent/dev/input/event0 3 0//start from point (100,200)
ADB shell sendevent/dev/input/event0 3 1 200
ADB shell sendevent/dev/input/event0 1 1//touch
ADB shell sendevent/dev/input/event0 0 0 0
ADB shell sendevent/dev/input/event0 3 0 101//step to point (101,200)
ADB shell sendevent/dev/input/event0 0 0 0
.....//must list Each step, here just skip, and .....????.
ADB shell sendevent/dev/input/event0 3 0 108//end Point (108,200)
ADB shell sendevent/dev/input/event0 0 0 0
adb shell sendevent/dev/input/event0 1 0//untouch
ADB shell sendevent/dev/input/event0 0 0 0
Examples are as follows:
Sendevent/dev/input/event4 3 0 258;sendevent/dev/input/event4 3 1 285;sendevent/dev/input/event4 1 1;sendevent/dev /input/event4 0 0 0; Sendevent/dev/input/event4 1 0;sendevent/dev/input/event4 0 0 0
Spreadtrum Platform Click on the coordinate point (380,870) event:
adb shell "sendevent dev/input/event4 1 1;sendevent dev/input/event4 3 20;sendevent dev/input/event4 3 380;sen Devent dev/input/event4 3 870;sendevent dev/input/event4 0 2 0;sendevent dev/input/event4 0 0 0;sendevent Dev/inpu T/event4 3 20;sendevent dev/input/event4 3 380;sendevent dev/input/event4 3 870;sendevent dev/input/event4 0 2 0;sendevent dev/input/event4 0 0 0;sendevent dev/input/event4 1 0;sendevent dev/input/event4 0 2 0;sendevent de V/input/event4 0 0 0 "
adb shell "sendevent dev/input/event4 1 1;sendevent dev/input/event4 3 20;sendevent dev/input/event4 3 &NB Sp;380;sendevent dev/input/event4 3 870;sendevent dev/input/event4 0 2 0;sendevent dev/input/event4 0 0 &N Bsp 0;sendevent dev/input/event4 1 0;sendevent dev/input/event4 0 0 0 "