tkinter实现可视化脚本
华为国内源下载 链接: https://mirrors.huaweicloud.com/python/3.8.0/
官网下载 链接: https://www.python.org/
我的c盘容量足够我就放在默认安装的位置了,如果c盘容量不够或者想方便找到就选 Customize installation
Install Now结束后弹出
即安装完成,可打开命令窗口(Win+R后输入cmd确认)输入python后出现如下画面即安装成功
Airtest官网下载 链接: http://airtest.netease.com/
进入后点击AGREE AND DOWNLOAD后即可下载
下载完成后解压即可 //如果没有解压工具可以下载一个winrar 官网链接: https://www.winrar.com.cn/
进入AirtestIDE文件夹后找到并打开AirtestIDE即可
如果不小心把窗口关了在窗口选择中勾选这些选项即可
写这个脚本主要要用的功能
打开模拟器后点击connect后即可连接。模拟器最好用雷电模拟器5.0版本,5.0版本对公主连结的优化好。雷电模拟器5.0官网下载链接: https://www.ldmnq.com/other/version-history-and-release-notes.html?log=5
点击Airtest辅助窗的touch
然后拖动框住需要点击的图标即可
touch功能会自动识别当前屏幕并找到框选的图标并中心点击,如果20s后还没找到就会报错并停止运行。
touch括号内还能加参数,times=5即点击5次。
Airtest中找到wait,与touch一样拖动框住需要等待的图标即可。
wait功能等待时间可以随意设置,默认等待60s,60秒后如果没有找到图片则报错并停止运行。
wait括号内也能加参数,timeout=120即设置等待时间为120秒。
Airtest中找到exists,与touch一样拖动框住需要等待的图标即可。
exists功能可以用来判断一些不是固定出现的窗口。
例如,用if判断报错后脚本不会停止运行,用if判断exists出错后,跳出if判断并运行下一行与if语句同行的代码。即不会运行下面的touch语句。
Airtest中找到sleep,点击sleep后就会在文本光标处生成代码。
sleep功能可以使脚本无条件等待,等待时间为sleep括号内的1.0单位秒。1.0即为1s。
这样组合可以使touch的等待时间超过20s,在timeout处设置等待时间。
这样组合可以判断一些不是固定出现的界面,使脚本可以稳定运行下去。
def dianjitubiao(): #def后使用tab。
touch(wait(Template(r"tpl1679931141723.png", record_pos=(-0.219, -0.165), resolution=(960, 540)),timeout=60))
这里为图片识别代码在Airtest中为一张图片
在主函数中,即可调用dianjitupian中的点击功能touch(wait(Template(r"tpl1679931141723.png", record_pos=(-0.219, -0.165), resolution=(960, 540)))
dianjitupian(): #使用定义中的点击功能。
使用6个功能就能完成公主连结自动刷日常的脚本了。
只要注意用if(exists( ))过掉一些不是固定出现的界面就可以顺利完成脚本了
1.打开雷典模拟器并进入点击公主连结游戏图标
2.进入公主连结游戏内的主页
3.领取家园体力
4.完成探索
5.完成调查
6.完成竞技场
7.完成公主竞技场
8.扫荡地下城
9.完成竞技场
10.公会点赞
11.领取邮件
12.完成竞技场
13.商店买体力药
14.领取任务奖励
使用python标准库os的os.startfile实现自动打开雷电模拟器。
改成自己模拟器所在的位置。
os.startfile('C:\游戏\雷电模拟器5公主连结\leidian\LDPlayer64\dnplayer.exe')
用代码连接雷电模拟器。
auto_setup(__file__,logdir=True,devices=["android:emulator-5554"])
os.startfile('C:\游戏\雷电模拟器5公主连结\leidian\LDPlayer64\dnplayer.exe')
sleep(25.0)
auto_setup(__file__,logdir=True,devices=["android:emulator-5554"])
touch(wait(Template(r"tpl1679931141723.png", record_pos=(-0.219, -0.165), resolution=(960, 540)),timeout=60)) #点击雷电模拟器主页的公主连结图片。
编辑内容为python untitled.py,之后双击cmd.bat文件即可运行脚本
公主连结脚本
模拟器配置,及屏幕配置不同。源码的参考价值不大。
# -*- encoding=utf8 -*-
__author__ = "宇宙技术"
import time
from airtest.core.api import *
auto_setup(__file__)
def jinrugongzhulianjie(): #进入游戏
# os.startfile( r'G:\游戏\雷电模拟器\leidian\LDPlayer4\dnplayer.exe') #os.startfile()打开外部应该程序,与windows双击相同
# time.sleep(15)
# auto_setup(__file__,logdir=True,devices=["android:emulator-5554"])
# start_app("com.bilibili.priconne")
wait(Template(r"tpl1679891883961.png", record_pos=(-0.425, 0.248), resolution=(960, 540)),timeout=60)
time.sleep(3)
touch([159,357])
time.sleep(15)
if(exists(Template(r"tpl1679912512594.png", record_pos=(0.0, -0.13), resolution=(960, 540)))):
touch([588,371])
time.sleep(40)
if(exists(Template(r"tpl1680153798361.png", record_pos=(0.451, -0.245), resolution=(960, 540)))):
touch(Template(r"tpl1680153798361.png", record_pos=(0.451, -0.245), resolution=(960, 540)))
# touch(wait(Template(r"tpl1680153798361.png", record_pos=(0.451, -0.245), resolution=(960, 540)),timeout=60))
time.sleep(5)
if(exists(Template(r"tpl1680611843062.png", record_pos=(0.456, -0.236), resolution=(960, 540)))):
touch(Template(r"tpl1680611843062.png", record_pos=(0.456, -0.236), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679996695873.png", record_pos=(0.343, -0.236), resolution=(960, 540)))
touch(Template(r"tpl1679996747203.png", record_pos=(0.114, 0.102), resolution=(960, 540)))
time.sleep(5)
if(exists(Template(r"tpl1680612133391.png", record_pos=(0.0, -0.05), resolution=(960, 540)))):#三周年活动
touch(Template(r"tpl1680612133391.png", record_pos=(0.0, -0.05), resolution=(960, 540)))
time.sleep(5)
if(exists(Template(r"tpl1679996695873.png", record_pos=(0.343, -0.236), resolution=(960, 540)))):
touch(Template(r"tpl1679996695873.png", record_pos=(0.343, -0.236), resolution=(960, 540)))
touch(Template(r"tpl1679996747203.png", record_pos=(0.114, 0.102), resolution=(960, 540)))
time.sleep(3)
touch([485,267])
if(exists(Template(r"tpl1681796950940.png", record_pos=(-0.407, -0.18), resolution=(960, 540)))):
touch([769,309])
time.sleep(3)
touch(Template(r"tpl1681797008683.png", record_pos=(0.377, 0.229), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1681797046977.png", record_pos=(0.147, 0.127), resolution=(960, 540)))
time.sleep(3)
touch(wait(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)),timeout=60))
time.sleep(5)
if(exists(Template(r"tpl1680612299287.png", record_pos=(0.002, -0.241), resolution=(960, 540)))):
touch(Template(r"tpl1679928956545.png", record_pos=(0.111, 0.215), resolution=(960, 540)))
if(exists(Template(r"tpl1683876441565.png", record_pos=(-0.12, 0.214), resolution=(960, 540)))):
touch(Template(r"tpl1683876441565.png", record_pos=(-0.12, 0.214), resolution=(960, 540)))
#进入游戏中的我的主页
def wancantansuo(): #完成探索
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(2)
touch(Template(r"tpl1679906812729.png", record_pos=(0.269, -0.1), resolution=(960, 540)))
time.sleep(2)
touch(Template(r"tpl1679906893408.png", record_pos=(0.11, 0.067), resolution=(960, 540)))
time.sleep(3)
touch([676,146]) #点击经验关11级
time.sleep(3)
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907120293.png", record_pos=(0.283, 0.065), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
if(exists(Template(r"tpl1683111593838.png", record_pos=(-0.007, 0.104), resolution=(960, 540)))):
touch(Template(r"tpl1683111593838.png", record_pos=(-0.007, 0.104), resolution=(960, 540)))
touch(Template(r"tpl1679907243548.png", record_pos=(-0.003, 0.216), resolution=(960, 540)))
time.sleep(3)
touch([817,146])
time.sleep(1)
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907120293.png", record_pos=(0.283, 0.065), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(5)
if(exists(Template(r"tpl1679907474856.png", record_pos=(-0.005, 0.001), resolution=(960, 540)))):
touch([461,362])
time.sleep(1)
touch(Template(r"tpl1679907556846.png", record_pos=(0.001, 0.217), resolution=(960, 540))) #完成探索
time.sleep(3)
touch([93,518]) #返回主页 #探索 #完成探索 #探索 #探索
def wancandiaocha1(): #圣迹调查
if (exists(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))):
touch(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))
time.sleep(3)
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(8)
touch(Template(r"tpl1679908038733.png", record_pos=(0.265, 0.045), resolution=(960, 540)))
time.sleep(5)
touch(Template(r"tpl1679908109660.png", record_pos=(0.11, 0.068), resolution=(960, 540)))
time.sleep(3)
touch([851,146])
time.sleep(2)
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)),times=5)
time.sleep(1)
touch(Template(r"tpl1679908487852.png", record_pos=(0.286, 0.064), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(1)
# # if(exists(Template(r"tpl1679908590232.png", record_pos=(-0.001, -0.051), resolution=(960, 540)))):
# touch([378,369])
if(exists(Template(r"tpl1681711655247.png", record_pos=(0.0, -0.24), resolution=(960, 540)))):
touch([588,473])
time.sleep(3)
touch([50,255])
# 进入圣迹调查关卡2级
time.sleep(2)
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)),times=5)
time.sleep(1)
touch(Template(r"tpl1679908487852.png", record_pos=(0.286, 0.064), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(1)
# # if(exists(Template(r"tpl1679908590232.png", record_pos=(-0.001, -0.051), resolution=(960, 540)))):
# touch([378,369])
if(exists(Template(r"tpl1681711655247.png", record_pos=(0.0, -0.24), resolution=(960, 540)))):
touch([588,473])
time.sleep(3)
touch([50,255])
time.sleep(1)
# 进入圣迹调查关卡1级
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)),times=5)
time.sleep(1)
touch(Template(r"tpl1679908487852.png", record_pos=(0.286, 0.064), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(1)
# if(exists(Template(r"tpl1679908590232.png", record_pos=(-0.001, -0.051), resolution=(960, 540)))):
# touch([378,369])
if(exists(Template(r"tpl1681711655247.png", record_pos=(0.0, -0.24), resolution=(960, 540)))):
touch([588,473])
time.sleep(3)
touch([660,452])
time.sleep(3)
touch([97,514]) #返回主页
def wancandiaocha2(): #神殿调查
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(1)
touch(Template(r"tpl1679908038733.png", record_pos=(0.265, 0.045), resolution=(960, 540)))
time.sleep(3)
touch([800,261])
time.sleep(3)
touch([841,145])
# 进入神殿调查关卡二级
time.sleep(2)
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)),times=5)
time.sleep(1)
touch(Template(r"tpl1679908487852.png", record_pos=(0.286, 0.064), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(1)
if(exists(Template(r"tpl1679909602956.png", record_pos=(0.0, -0.191), resolution=(960, 540)))):
touch([358,429])
time.sleep(1)
# if(exists(Template(r"tpl1679908590232.png", record_pos=(-0.001, -0.051), resolution=(960, 540)))):
# touch([378,369])
if(exists(Template(r"tpl1681711655247.png", record_pos=(0.0, -0.24), resolution=(960, 540)))):
touch([588,473])
time.sleep(3)
touch([50,255])
time.sleep(1)
# 进入神殿调查关卡一级
touch(Template(r"tpl1679907076278.png", record_pos=(0.416, 0.062), resolution=(960, 540)),times=5)
time.sleep(1)
touch(Template(r"tpl1679908487852.png", record_pos=(0.286, 0.064), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(1)
if(exists(Template(r"tpl1679909602956.png", record_pos=(0.0, -0.191), resolution=(960, 540)))):
touch([358,429])
time.sleep(1)
# if(exists(Template(r"tpl1679908590232.png", record_pos=(-0.001, -0.051), resolution=(960, 540)))):
# touch([378,369])
if(exists(Template(r"tpl1681711655247.png", record_pos=(0.0, -0.24), resolution=(960, 540)))):
touch([588,473])
time.sleep(3)
touch([667,457])
time.sleep(3)
touch([97,514]) #返回主页
def jinjichang(): #战斗竞技场
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(3)
touch([555,414])
time.sleep(3)
if(exists(Template(r"tpl1679910512931.png", record_pos=(-0.41, -0.036), resolution=(960, 540)))):
touch([751,414])
time.sleep(3)
touch([751,414])
time.sleep(8)
touch(Template(r"tpl1679910571276.png", record_pos=(0.372, 0.192), resolution=(960, 540)))
touch(wait(Template(r"tpl1679910711507.png", record_pos=(0.368, 0.229), resolution=(960, 540)),timeout=60))
time.sleep(5)
touch([90,515]) #返回我的主页
time.sleep(5)
touch([90,515])
def gongzhujingjichang(): #公主竞技场
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(3)
touch([812,418])
if(exists(Template(r"tpl1679910512931.png", record_pos=(-0.41, -0.036), resolution=(960, 540)))):
touch([751,414])
time.sleep(5)
touch([829,447])
time.sleep(5)
touch([829,447])
touch(Template(r"tpl1679910571276.png", record_pos=(0.372, 0.192), resolution=(960, 540)))
touch(wait(Template(r"tpl1679910711507.png", record_pos=(0.368, 0.229), resolution=(960, 540)),timeout=180))
time.sleep(5)
touch([90,515]) #返回我的主页
time.sleep(5)
touch([90,515])
def dixiacheng():
if (exists(Template(r"tpl1679906603793.png", record_pos=(0.338, -0.239), resolution=(960, 540)))):
touch([487,522]) #进入冒险
time.sleep(3)
touch(Template(r"tpl1679927239527.png", record_pos=(0.414, -0.099), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1681912795648.png", record_pos=(0.131, 0.08), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1681712042808.png", record_pos=(-0.001, 0.17), resolution=(960, 540)))
time.sleep(20)
touch(Template(r"tpl1681712072204.png", record_pos=(-0.004, 0.218), resolution=(960, 540)))
time.sleep(3)
if(exists(Template(r"tpl1682923978998.png", record_pos=(-0.004, 0.218), resolution=(960, 540)))):
touch(Template(r"tpl1682923978998.png", record_pos=(-0.004, 0.218), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1681712102220.png", record_pos=(-0.403, 0.263), resolution=(960, 540)))
def shouyoujian(): #收邮件
touch(Template(r"tpl1679928813166.png", record_pos=(0.449, 0.185), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679928853347.png", record_pos=(0.341, 0.212), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679908552156.png", record_pos=(-0.005, 0.216), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679928956545.png", record_pos=(0.111, 0.215), resolution=(960, 540)))
def renwu(): #任务收取
touch(Template(r"tpl1679929144943.png", record_pos=(0.375, 0.178), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679928853347.png", record_pos=(0.341, 0.212), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679928685719.png", record_pos=(-0.405, 0.265), resolution=(960, 540))) #收任务 #收任务
def gonghuidianzhan(): #工会点赞
touch(Template(r"tpl1679929320374.png", record_pos=(0.221, 0.176), resolution=(960, 540)))
time.sleep(5)
if(exists(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))):
touch(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))
time.sleep(8)
touch(Template(r"tpl1679930106792.png", record_pos=(-0.256, 0.09), resolution=(960, 540)))
time.sleep(8)
touch([823,199])
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(3)
touch([89,518])
def shangdianmaiyao(): #商店买药
touch(Template(r"tpl1679930403487.png", record_pos=(0.14, 0.172), resolution=(960, 540)))
time.sleep(3)
touch([383,192])
touch([560,185])
touch([732,190])
touch([900,195])
time.sleep(3)
touch([786,435])
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1679907191536.png", record_pos=(0.117, 0.101), resolution=(960, 540)))
touch(Template(r"tpl1679928685719.png", record_pos=(-0.405, 0.265), resolution=(960, 540)))
def guojuqing(): #过剧情(未完成)
touch(Template(r"tpl1679996415555.png", record_pos=(-0.149, 0.265), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679996450975.png", record_pos=(0.37, -0.169), resolution=(960, 540)))
time.sleep(1)
touch([830,123])
time.sleep(1)
# 过剧情
touch([856,253])
time.sleep(1)
touch([481,372])
time.sleep(1)
touch(wait(Template(r"tpl1679996651101.png", record_pos=(0.458, -0.237), resolution=(960, 540)),timeout=100))
time.sleep(1)
touch(Template(r"tpl1679996695873.png", record_pos=(0.343, -0.236), resolution=(960, 540)))
time.sleep(1)
touch(Template(r"tpl1679996747203.png", record_pos=(0.114, 0.102), resolution=(960, 540)))
time.sleep(1)
touch([321,289])
time.sleep(1)
touch(Template(r"tpl1679996747203.png", record_pos=(0.114, 0.102), resolution=(960, 540)))
touch(wait(Template(r"tpl1679996651101.png", record_pos=(0.458, -0.237), resolution=(960, 540)),timeout=100))
time.sleep(3)
touch(Template(r"tpl1679996695873.png", record_pos=(0.343, -0.236), resolution=(960, 540)))
touch(Template(r"tpl1679996747203.png", record_pos=(0.114, 0.102), resolution=(960, 540)))
touch(Template(r"tpl1679905113513.png", record_pos=(-0.005, 0.217), resolution=(960, 540)))
def lingqutili():
touch(Template(r"tpl1683800539020.png", record_pos=(0.152, 0.26), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1683800578044.png", record_pos=(0.439, 0.171), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1683800595617.png", record_pos=(-0.003, 0.218), resolution=(960, 540)))
time.sleep(3)
touch(Template(r"tpl1683800606788.png", record_pos=(-0.401, 0.263), resolution=(960, 540)))
os.startfile('C:\游戏\雷电模拟器5公主连结\leidian\LDPlayer64\dnplayer.exe') #os.startfile()打开外部应该程序,与windows双击相同
time.sleep(25)
auto_setup(__file__,logdir=True,devices=["android:emulator-5554"])
touch(wait(Template(r"tpl1679931141723.png", record_pos=(-0.219, -0.165), resolution=(960, 540)),timeout=60))
jinrugongzhulianjie()
time.sleep(3)
lingqutili()
time.sleep(3)
wancantansuo()
time.sleep(3)
wancandiaocha1()
time.sleep(3)
wancandiaocha2()
time.sleep(3)
jinjichang()
time.sleep(3)
gongzhujingjichang()
time.sleep(3)
dixiacheng()
time.sleep(3)
shouyoujian()
time.sleep(3)
gonghuidianzhan()
time.sleep(3)
shangdianmaiyao()
time.sleep(3)
renwu()