雷电模拟器+python

import os
import time
from compare import compare #上一段代码我存为了compare.py
 
class Ldconsole: #请根据自己软件的路径来
    console = r'F:\leidian\LDPlayer9\dnconsole.exe '
    ld = r'F:\leidian\LDPlayer9\ld.exe'
    adb = r'F:\leidian\LDPlayer9\adb.exe'  
#这个类其实不用写的(个人意见),参照于http://t.csdnimg.cn/rkTDh,下面使用ld和console的也是基于此博客
 
    def launch(self,index: int): #启动函数
        cmd = Ldconsole.console + 'launch --index ' + str(index)
 #可以去雷电官方论坛看console和ld的使用格式和函数用途
        process = os.popen(cmd) #os是python向cmd发送指令的库
        result = process.read() #结果读取
        process.close()
        return result #结果显示
 
    def app_star(self,index: int, package: str):
#启动app,等会函数内填的是应用名,自行查app调用名(例如:com.bilibili.umamusu(赛马娘,启动!),应该是和安装包同名)
        cmd = Ldconsole.console + 'runapp --index %d --packagename %s' % (index, package)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result
 
 
    def adb_start(self,index: int): #启动adb的函数,这段里面注释掉的是本来应该写在这,但是不注释就报错,但为了纪念我去查资料的时间,所以我留着了ᕕ(◠ڼ◠)ᕗ
        #cmd1 ='adb kill-server' 本来在启动要结束之前启动的adb的
        #process = os.popen(cmd1)
        #result = process.read()
        #process.close()
        #print(result)
        #return result
        cmd2 = 'adb start-server'
        process = os.popen(cmd2)
        process.close()
        cmd3 = Ldconsole.adb + ' connect 127.0.0.1:5555' #连接到雷电模拟器的端口号,第一次应该连接不上(我也不知为什么,第一次会自动连接到 emulator-5554),cmd可查此时连接上adb的模拟器的端口号,自行学习
        process = os.popen(cmd3)
        process.close()
        #return result
 
    def tap(self, a, b):#用于点击的函数
        cmd = Ldconsole.adb + ' -s emulator-5554  shell input tap {x} {y}'.format(x=a,y=b)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result
 
    def screencap(self,index: int,str): #截屏
        cmd = (Ldconsole.adb +
        ' -s emulator-5554 shell /system/bin/screencap -p /sdcard/{name}.png'.format(name=str))
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result
 
    def screenget(self,index: int,str): #将截屏存放到F:\python\pythonProject(这是我的路径,记得自行更改)
        cmd = (Ldconsole.adb +
        ' -s emulator-5554  pull /sdcard/{name}.png F:\python\pythonProject'.format(name=str))
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result
 
    def kill_self(self,index: int): #写到这我才发现还是写了个结束进程的函数。。
        cmd ='adb kill-server'
        process = os.popen(cmd)
        result = process.read()
        process.close()
        print(result)
        return result
 
          
    def main():
        a = Ldconsole()# 打开模拟器
        a.tap(646, 1524)  
        a.tap(646, 1524)  
        a.launch(0) #这里很多延时是因为响应速度问题,删除可能导致某一步没执行
        time.sleep(4)
        a.kill_self(0)
        time.sleep(4)
        a.adb_start(0)
        time.sleep(4)
        #time.sleep(3)
        a.app_star(0,'com.bilibili.umamusu')
        #time.sleep(10)
        #a.tap(590,250) #启动应用的坐标
        time.sleep(18)
        a.screencap(0,'screengap')
        time.sleep(1)
        a.screenget(0,'screengap')
        time.sleep(2)
        x=compare(0,0,0,0,0,"enter") #基于compare.py见上一段
        if x>0.82:
            a.tap(590,250)
        time.sleep(30)
        a.screencap(0,'screengap')
        time.sleep(2)
        a.screenget(0,'screengap')
        x=compare(0,0,0,0,0,"mainscreen")
        if x >= 0.82:
            competition()
        else:
            print("error")
            exit(0)
    
    
        #a.kill_self(0)
        #a.quit(0)
    
if __name__ == '__main__':
    main()

其他:

Python - 控制雷电模拟器(Dnconsole)_python控制雷电模拟器-CSDN博客

相关推荐

  1. 雷电模拟器+python

    2024-04-20 20:32:01       14 阅读
  2. Python创建语音模拟器

    2024-04-20 20:32:01       41 阅读
  3. Python小项目 - 人生重开模拟器

    2024-04-20 20:32:01       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-20 20:32:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-20 20:32:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-20 20:32:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-20 20:32:01       18 阅读

热门阅读

  1. 实习学习内容-Lua语法

    2024-04-20 20:32:01       14 阅读
  2. mac 使用nvm配置nodejs

    2024-04-20 20:32:01       13 阅读
  3. 数据结构,算法(一)--排序

    2024-04-20 20:32:01       14 阅读
  4. React官网力荐Next.js:为何它取代了Create-React-App?

    2024-04-20 20:32:01       13 阅读
  5. 习题4-1 求奇数和

    2024-04-20 20:32:01       10 阅读
  6. 数据结构与算法:常用的启发式算法

    2024-04-20 20:32:01       12 阅读
  7. 解决向MySQL中导入文件中的 数据时出现的问题~

    2024-04-20 20:32:01       11 阅读
  8. 2024/4/19 MySQL索引结构

    2024-04-20 20:32:01       12 阅读
  9. MySQL 解压版安装后忘记密码如何处理

    2024-04-20 20:32:01       11 阅读
  10. 【力扣 | 分享】高频 SQL 50 题(基础版)

    2024-04-20 20:32:01       11 阅读
  11. 完全平方数

    2024-04-20 20:32:01       11 阅读