python模擬android屏幕高頻點擊工具


 

 

一、環境

    windows 10  + python3.6

二、需求

    1、模擬android設備高頻點擊事件;

    2、模擬規定次數的點擊事件或模擬規定時間內的點擊事件;

三、code

    1、模擬規定時間內的點擊事件 

 1 #!/usr/bin/env python3 
 2 # coding=utf-8
 3 
 4 import subprocess
 5 import time
 6 
 7 
 8 def loop_click_for_android(run_time=5):
 9     res = subprocess.Popen('adb devices',
10                            shell=True, stdout=subprocess.PIPE)
11     res.stdout.read()
12     inputs = str(input("請確保已打開測試頁面(y/n): "))
13 
14     if inputs == "y":
15         num = 0
16         node_time = time.time()
17         start_buttun = subprocess.Popen("adb shell input tap 600 1660")
18         if start_buttun:
19             while True:
20                 result = subprocess.Popen("adb shell input tap 600 1660")
21                 if result:
22                     num += 1
23                     if node_time + run_time <= time.time():
24                         break
25                     else:
26                         continue
27         print("發送點擊次數{}".format(num))   # 次數統計並不准確
28     else:
29         print("程序關閉~")
30         exit(1)
31 
32 
33 loop_click_for_android()

    2、模擬規定次數的點擊事件

 1 # !/usr/bin/env python3
 2 # coding=utf-8
 3 
 4 import subprocess
 5 import time
 6 
 7 
 8 def loop_click_for_android(run_num=150):
 9     res = subprocess.Popen('adb devices',
10                            shell=True, stdout=subprocess.PIPE)
11     res.stdout.read()
12     inputs = str(input("請確保已打開測試頁面(y/n): "))
13 
14     if inputs == "y":
15         num = 0
16         node_time = time.time()
17         start_buttun = subprocess.Popen("adb shell input tap 600 1660")
18         if start_buttun:
19             while True:
20                 result = subprocess.Popen("adb shell input tap 600 1100")
21                 if result:
22                     num += 1
23                     if num == run_num:
24                         break
25                     else:
26                         continue
27         over_time = time.time()
28         print("{}次點擊的運行時間是:{}".format(run_num, over_time-node_time))   # 次數統計並不准確
29     else:
30         print("程序關閉~")
31         exit(1)
32 
33 
34 loop_click_for_android()

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM