First, the environment
Windows Ten + python3.6
Second, demand
1, analog Android device high-frequency click event;
2. Simulate the Click event of the specified number of times or simulate the click event within the specified time;
Third, code
1. Simulate Click events within a specified time
1 #!/usr/bin/env Python32 #Coding=utf-83 4 Importsubprocess5 Import Time6 7 8 defLoop_click_for_android (run_time=5):9res = subprocess. Popen ('ADB devices',TenShell=true, stdout=subprocess. PIPE) One Res.stdout.read () Ainputs = str (input ("Make sure the test page (y/n) is open:")) - - ifInputs = ="y": thenum =0 -Node_time =time.time () -Start_buttun = subprocess. Popen ("adb shell input tap 1660") - ifStart_buttun: + whileTrue: -result = subprocess. Popen ("adb shell input tap 1660") + ifResult: Anum + = 1 at ifNode_time + run_time <=time.time (): - Break - Else: - Continue - Print("send clicks {}". Format (num))#count is not accurate - Else: in Print("Program Close ~") -Exit (1) to + -Loop_click_for_android ()
2. Simulate a specified number of click events
1 #!/usr/bin/env Python32 #Coding=utf-83 4 Importsubprocess5 Import Time6 7 8 defLoop_click_for_android (run_num=150):9res = subprocess. Popen ('ADB devices',TenShell=true, stdout=subprocess. PIPE) One Res.stdout.read () Ainputs = str (input ("Make sure the test page (y/n) is open:")) - - ifInputs = ="y": thenum =0 -Node_time =time.time () -Start_buttun = subprocess. Popen ("adb shell input tap 1660") - ifStart_buttun: + whileTrue: -result = subprocess. Popen ("adb shell input tap 1100") + ifResult: Anum + = 1 at ifnum = =Run_num: - Break - Else: - Continue -Over_time =time.time () - Print("{} times the run time of the click is: {}". Format (Run_num, over_time-node_time))#count is not accurate in Else: - Print("Program Close ~") toExit (1) + - theLoop_click_for_android ()
Python analog Android Screen high frequency click Tool