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()
复制代码

 

 

 

作者:medivhxu

出处:https://www.cnblogs.com/medivhxu/p/8492608.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Medivh_Xu  阅读(5102)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up light_mode palette
选择主题