首页 文章 精选 留言 我的

精选列表

搜索[系统工具],共10000篇文章
优秀的个人博客,低调大师

Python写一个Windows下的android设备截图工具

界面版 利用python的wx库写个ui界面,用来把android设备的截图输出到电脑屏幕,前提需要安装adb,涉及到的python库也要安装。代码如下: import wx,subprocess,os,platform class AutyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Android Auty', size=(350, 300)) self.panel = wx.Panel(self, -1) #Android devices combox. combox_list = [] r = execute_shell("adb devices") for i in range(1,len(r)-1): if r[i].startswith("*") and r[i].endswith("*"): pass else: combox_list.append(r[i].split("\t")[0]) wx.StaticText(self.panel, -1, "Select devices:", (15, 15)) self.devices_combobox = wx.ComboBox(self.panel, -1, r[1].split("\t")[0], (15, 35), wx.DefaultSize, combox_list, wx.CB_DROPDOWN) #Capture button. self.capture_button = wx.Button(self.panel, -1, "capture", pos=(188, 35), size=(66,25)) self.reload_button = wx.Button(self.panel, -1, "reload", pos=(258, 35), size=(66,25)) self.Bind(wx.EVT_BUTTON, self.captureClick, self.capture_button) self.Bind(wx.EVT_BUTTON, self.reloadClick, self.reload_button) self.capture_button.SetDefault() self.reload_button.SetDefault() def captureClick(self, event): capture_android(self.devices_combobox.GetValue()) if("Windows" in platform.platform()): os.startfile("d:\\screenshot.png") def reloadClick(self, event): self.devices_combobox.Clear() k = execute_shell("adb devices") for i in range(1,len(k)-1): self.devices_combobox.Append(k[i].split("\t")[0]) self.devices_combobox.SetValue(k[1].split("\t")[0]) def execute_shell(shell): p = subprocess.Popen(shell,shell=True,stdout=subprocess.PIPE) out = p.stdout.readlines() return out def capture_android(device_id): sh1 = "adb -s "+device_id+" shell /system/bin/screencap -p /sdcard/screenshot.png" sh2 = "adb -s "+device_id+" pull /sdcard/screenshot.png d:/screenshot.png" execute_shell(sh1) execute_shell(sh2) if __name__ == '__main__': app = wx.PySimpleApp() AutyFrame().Show() app.MainLoop() 运行截图: 优点: 1. 比uiautomatorviewer运行速度快,比monitor更快; 2. 可以针对多个设备,选择性进行截屏; 3. 截屏以后截图(保存在D盘根目录下“screenshot.png”文件)会自动打开; 4. 插拔设备后可以reload重新加载设备列表。 命令行版 如果不想安装wx库,提供一个命令行版的安卓截屏python脚本(capture_android.py): import sys,os,platform from execute_shell import execute_shell def capture_android(device_id): sh1 = "adb -s "+device_id+" shell /system/bin/screencap -p /sdcard/screenshot.png" sh2 = "adb -s "+device_id+" pull /sdcard/screenshot.png d:/screenshot.png" execute_shell(sh1) execute_shell(sh2) if __name__ == '__main__': if len(sys.argv) == 2: device_id = sys.argv[1] capture_android(sys.argv[1]) if("Windows" in platform.platform()): os.startfile("d:\\screenshot.png") 引用的execute_shell.py内容如下(把引用的文件放在同级目录下就行): import subprocess def execute_shell(shell): p = subprocess.Popen(shell,shell=True,stdout=subprocess.PIPE) out = p.stdout.readlines() return out 使用方法(python 脚本路径 device_id参数): 截屏后图片会自动打开。

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册