iis服务器助手广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python实现adb辅助点击屏幕工具
  • 623
分享到

python实现adb辅助点击屏幕工具

pythonadb开发语言屏幕点击 2023-09-13 11:09:11 623人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

#!/usr/bin/env python# -*- coding: utf-8 -*-import reimport osimport timeimport subprocessimport tkinter as tkfrom tkint

#!/usr/bin/env python# -*- coding: utf-8 -*-import reimport osimport timeimport subprocessimport tkinter as tkfrom tkinter import messageboxfrom PIL import Image, ImageTk# 设置ADB路径(根据你的系统和安装路径进行调整)ADB_PATH = 'C:/Users/DHY-20210315/AppData/Local/Android/Sdk/platform-tools/adb.exe'# 设置截屏图片显示比例scl = 0.7# 创建一个GUI窗口root = tk.Tk()root.title("ADB辅助点击助手")screen_width = root.winfo_screenwidth()screen_height = root.winfo_screenheight()# 设置窗口大小window_width = 900window_height = 600x = (screen_width - window_width) // 2y = (screen_height - window_height) // 2root.geometry(f"{window_width}x{window_height}+{x}+{y}")# 函数:通过ADB截屏并显示def capture_and_display():    if r_var.get() == '':        messagebox.showinfo(title='提示', message='没有连接设备呀!')        return    # file = str(round(time.time() * 1000)) + '.png'    file = 'screencap.png'    scp = '/sdcard/Pictures/' + file    capture_process = subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'shell', 'screencap', scp])    capture_process.wait()    lsc = './' + file    pull_process = subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'pull', scp, lsc])    pull_process.wait()    screenshot = Image.open(lsc)    width, height = screenshot.size    new_width = int(width * scl)    new_height = int(height * scl)    screenshot = screenshot.resize((new_width, new_height), Image.ANTIALIAS)    s_w = new_width + 20    s_h = new_height + 50    root.geometry(f"{s_w}x{s_h}+{(screen_width - s_w) // 2}+{(screen_height - s_h) // 2}")    img = ImageTk.PhotoImage(screenshot)    img_label.config(image=img)    img_label.image = img# 函数:通过ADB点击图片def click_img(event):    if r_var.get() == '':        messagebox.showinfo(title='提示', message='没有连接设备呀!')        return    if ck_var.get() == 1:        for i in range(8):            subprocess.Popen(                [ADB_PATH, '-s', r_var.get(), 'shell', 'input', 'tap', str(event.x / scl), str(event.y / scl)])            time.sleep(0.01)        ck_var.set(0)    else:        subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'shell', 'input', 'tap', str(event.x / scl), str(event.y / scl)])    time.sleep(1)    capture_and_display()# 函数:通过ADB发送按键def send_back_command():    if r_var.get() == '':        messagebox.showinfo(title='提示', message='没有连接设备呀!')        return    subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'shell', 'input', 'keyevent', '4'])    time.sleep(1)    capture_and_display()# 函数:通过ADB发送滑动def send_slide_command(arg):    if r_var.get() == '':        messagebox.showinfo(title='提示', message='没有连接设备呀!')        return    if arg == 1:        subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'shell', 'input', 'swipe', '969 1050 969 800 100'])        time.sleep(1)        capture_and_display()    else:        subprocess.Popen([ADB_PATH, '-s', r_var.get(), 'shell', 'input', 'swipe', '969 800 969 1050 100'])        time.sleep(1)        capture_and_display()# 函数:通过ADB获取设备名def find_device():    dvs = os.popen("adb devices").readlines()    dfs = ''    for ss in dvs:        ss = ss.strip('\n')        if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:            dv = ss.split('\t')[0]            p = subprocess.Popen("adb -s %s shell getprop ro.product.model" % dv, stdout=subprocess.PIPE)            result = p.communicate()            dn = result[0].decode('utf-8').strip()            cold_bev = tk.Radiobutton(button_frame, text=dn, variable=r_var, value=dv)            cold_bev.pack(side="left")            if dfs == '':                dfs = dv    if dfs != '':        r_var.set(dfs)def find_ip(input_string):    ip_pattern = r'\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b'    ip_addresses = re.findall(ip_pattern, input_string)    return ip_addresses[0]# 函数:通过ADB wifi连接设备def wifi_connect():    if r_var.get() == '':        messagebox.showinfo(title='提示', message='没有连接设备呀!')        return    dv = r_var.get()    if r_var.get().startswith('192.168.'):        messagebox.showinfo(title='提示', message='已经是WiFi连接了啊!')        return    p = subprocess.Popen("adb -s %s shell ip -f inet addr show wlan0" % dv, stdout=subprocess.PIPE)    result = p.communicate()    dn = result[0].decode('utf-8').strip()    ip = find_ip(dn)    subprocess.Popen([ADB_PATH, 'connect', ip])button_frame = tk.Frame(root)button_frame.pack()capture_button = tk.Button(button_frame, text="截屏", command=capture_and_display)capture_button.pack(side="left")tk.Label(button_frame, text="   ").pack(side="left")back_button = tk.Button(button_frame, text="后退", command=send_back_command)back_button.pack(side="left")tk.Label(button_frame, text="   ").pack(side="left")up_button = tk.Button(button_frame, text="上滑", command=lambda: send_slide_command(1))up_button.pack(side="left")tk.Label(button_frame, text="   ").pack(side="left")down_button = tk.Button(button_frame, text="下滑", command=lambda: send_slide_command(0))down_button.pack(side="left")tk.Label(button_frame, text="   ").pack(side="left")ck_var = tk.IntVar()c1 = tk.Checkbutton(button_frame, text='8连击', variable=ck_var, onvalue=1, offvalue=0)c1.pack(side="left")tk.Label(button_frame, text="   ").pack(side="left")r_var = tk.StringVar(value='')find_device()img_label = tk.Label(root)img_label.pack()img_label.bind('', click_img)wifi_button = tk.Button(button_frame, text="WiFi连接", command=wifi_connect)wifi_button.pack(side="left")root.mainloop()

来源地址:https://blog.csdn.net/qq1053781225/article/details/132763435

--结束END--

本文标题: python实现adb辅助点击屏幕工具

本文链接: https://www.lsjlt.com/news/405750.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • python实现adb辅助点击屏幕工具
    #!/usr/bin/env python# -*- coding: utf-8 -*-import reimport osimport timeimport subprocessimport tkinter as tkfrom tkint...
    99+
    2023-09-13
    python adb 开发语言 屏幕点击
  • [python小工具]实现屏幕录制
      用python实现屏幕录制 PIL 即pollow 的安装命令如下: pip install pillow 其中cv2的安装是下面这条命令 pip install opencv-python #python + opencv 实...
    99+
    2023-01-31
    小工具 屏幕 python
  • Python做屏幕录制工具的实现示例
    目录思路实现录制监听键盘事件主体控制视频信息女朋友是一个软件测试人员,在工作中经常会遇到需要录屏记录自己操作,方便后续开发同学定位。因为录屏软件动不动就开始收费,所以她经常更换录屏软...
    99+
    2024-04-02
  • Java实现屏幕截图工具的代码分享
    目录效果展示程序结构核心代码效果展示 程序运行后的截图: 先测试一下功能: 截图过程对界面的捕捉: 双击保存后的显示界面: 后续的步骤就自己去尝试吧,这里给出了简单的测试过程。...
    99+
    2024-04-02
  • Java实现屏幕截图工具的代码怎么写
    这篇文章主要讲解了“Java实现屏幕截图工具的代码怎么写”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java实现屏幕截图工具的代码怎么写”吧!效果展示程序运行后的截图:先测试一下功能:截图...
    99+
    2023-06-30
  • python如何实现的截屏工具
    这篇文章主要介绍python如何实现的截屏工具,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!python的数据类型有哪些python的数据类型:1. 数字类型,包括int(整型)、long(长整型)和float(浮点...
    99+
    2023-06-14
  • python在屏幕上点击特定按钮或图像效果实例
    目录想要的效果需要用到的函数库PyAutoGUI——图形用户界面自动化(主要用到这个)Pillow——图像处理OpenCV&mdash...
    99+
    2024-04-02
  • win7系统下使用print screen键加画图工具实现屏幕截图
    截图大家应该都会,我们在QQ上聊天的时候,经常会截图给好友看,往往自己电脑上都会保存一些搞笑幽默的图片,到时候在QQ群里,或者论坛贴吧里发给别人欣赏,像笔者电脑的大部分图片都是在上网的时候,遇见搞笑,有意思的图片,就使用...
    99+
    2023-06-05
    win7 画图工具 屏幕截图 画图 print screen 系统 工具
  • 微信小程序如何实现点击item使其滚动到屏幕中间位置
    这篇文章将为大家详细讲解有关微信小程序如何实现点击item使其滚动到屏幕中间位置,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.需求想做类似猫眼电影选场次会自动滚动到屏...
    99+
    2024-04-02
  • python实现一般游戏的自动点击具体操作
    需要的软件: pycharm(pycharm安装步骤) 沙盒软件,例如:sandbox(百度搜索自行安装,如有需要可留言),360隔离沙盒 你的游戏 具体...
    99+
    2024-04-02
  • Python 工具类实现大文件断点续传功能详解
    依赖 os、sys、requests 工具代码 废话不多说,上代码。 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Cre...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作