Because of the work, need to use the analog input this thing, look up some information, the implementation of a variety of ways, I can be divided into two categories, command line class and program class.
The command line class includes the Automation Test Component Monkeyrunner,getevent/setevent Command, the input command
Program classes include Motionevent,accessibilityservice, reflection, etc.
I am also just contact with this piece, several ways do not judge the merits and demerits, only the work used in the knowledge points to record, for later use.
1. command line to open and close apps
ADB shell am START-N package Name/ENTRY activity // open an app adb shell am force-stop package name // close an app /c6>
2. Input command parameters
Usage:input [<source>] <command> [<arg>...] The sources Are:trackball//Rolling BallJoystick//JoystickTouchnavigation//Touch NavigationMouse//MouseKeyboard//keyboardGamePad//HandleTouchpad//Touch PadDpad//Analog HandleStylus//Sharp PenTouchscreen//Touch ScreenThe commands anddefaultsources Are:text<string>(Default:touchscreen)//Input text keyevent [--longpress] <key code number or name> ... (Default:keyboard)//keyboard operation Tap<x> <y>(Default:touchscreen)//click Swipe<x1> <y1> <x2> <y2>[Duration (ms)] (Default:touchscreen)//sliding operation Press (Default:trackball) Roll<dx> <dy> (Default:trackball)
One of the most common is keyboard and touchscreen, which is very simple to use.
3, keyevent value corresponding table
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" Ten-"Keycode_3" One-"Keycode_4" A-"keycode_5" --"Keycode_6" --"keycode_7" the-"Keycode_8" --"Keycode_9" --"Keycode_star" --"Keycode_pound" +-"keycode_dpad_up" --"Keycode_dpad_down" +-"Keycode_dpad_left" A-"Keycode_dpad_right" at-"Keycode_dpad_center" --"keycode_volume_up" --"Keycode_volume_down" --"Keycode_power" --"Keycode_camera" --"Keycode_clear" in-"keycode_a" --"Keycode_b" to-"Keycode_c" +-"keycode_d" --"keycode_e" the-"Keycode_f" *-"Keycode_g" $-"Keycode_h" Panax Notoginseng-"keycode_i" --"Keycode_j" the-"Keycode_k" +-"keycode_l" A-"keycode_m" the-"Keycode_n" +-"Keycode_o" --"keycode_p" $-"keycode_q" $-"Keycode_r" --"keycode_s" --"keycode_t" the-"Keycode_u" --"Keycode_v" Wuyi-"Keycode_w" the-"keycode_x" --"keycode_y" Wu-"keycode_z" --"Keycode_comma" About-"Keycode_period" $-"Keycode_alt_left" --"Keycode_alt_right" --"Keycode_shift_left" --"Keycode_shift_right" A-"Keycode_tab" +-"Keycode_space" the-"Keycode_sym" --"Keycode_explorer" $-"Keycode_envelope" the-"Keycode_enter" the-"Keycode_del" the-"Keycode_grave" the-"Keycode_minus" --"keycode_equals" in-"Keycode_left_bracket" the-"Keycode_right_bracket" the-"Keycode_backslash" About-"Keycode_semicolon" the-"Keycode_apostrophe" the-"Keycode_slash" the-"Keycode_at" +-"Keycode_num" --"Keycode_headsethook" the-"Keycode_focus"Bayi-"Keycode_plus" the-"Keycode_menu" the-"keycode_notification" --"Keycode_search" --"Tag_last_keycode"
4, Getevent/sendevent
First, execute the getevent-p command to get all input devices on the Android device and locate the screen device
Executes the getevent device number, performs the operation on the screen, and records the results of the getevent.
Type,code,value 0003 0036 000002a4
It is important to note that the value obtained by the getevent is 16 binary, Sendevent is sent 10 binary, need to do a conversion
Android analog input that's something.