当前位置:   article > 正文

python控制雷电模拟器 代码修复_易语言判断指定模拟器是否运行

易语言判断指定模拟器是否运行
  1. from concurrent.futures import thread
  2. import winreg, os ,time # 雷电模拟器自动获取目录使用
  3. import random
  4. #----------------------------------------------------------------
  5. def get_ldconsole(pro_name):
  6. def get_ld_dir():
  7. try:
  8. key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, "Software\ChangZhi2\dnplayer")
  9. v = winreg.QueryValueEx(key, "InstallDir")
  10. winreg.CloseKey(key)
  11. return v[0]
  12. except Exception as e:
  13. print(e)
  14. return "没有找到模拟器路径"
  15. return os.path.join(get_ld_dir(), pro_name)
  16. console1 = get_ldconsole("ldconsole.exe")
  17. console = console1.replace('\\','\\\\')
  18. ld1 = get_ldconsole("ld.exe")
  19. ld = ld1.replace('\\','\\\\')
  20. #----------------------------------------------------------------
  21. class Dnconsole:
  22. # 模拟器信息配置
  23. # ldpath = 'D:\\ChangZhi\\dnplayer2\\'
  24. # console = 'D:\\ChangZhi\\dnplayer2\\ldconsole.exe'
  25. # ld = 'D:\\ChangZhi\\dnplayer2\\ld.exe'
  26. #获取模拟器列表 修复完成
  27. @staticmethod
  28. def get_list():
  29. cmd = os.popen('{} list2'.format(console))
  30. text = cmd.read()
  31. cmd.close()
  32. info = text.split('\n')
  33. result = list()
  34. for line in info:
  35. if len(line) > 1:
  36. dnplayer = line.split(',')
  37. result.append(dnplayer)
  38. return result
  39. #获取正在运行的模拟器列表 修复完成 返回模拟器列表信息
  40. @staticmethod
  41. def list_running() -> list:
  42. result = list()
  43. all = Dnconsole.get_list()
  44. for dn in all:
  45. if dn[2] != '0':
  46. result.append(dn)
  47. return result
  48. #检测指定序号的模拟器是否正在运行 修复完成 返回模拟器信息
  49. @staticmethod
  50. def is_running(index: int) -> bool:
  51. all = Dnconsole.list_running()
  52. for i in all:
  53. if index == int(i[0]):
  54. return i
  55. else: return '检查【{}】号模拟器是否在运行'.format(index)
  56. #执行shell命令 ld控制adb 控制模拟器本身ldconsole从中模拟器游戏动作
  57. @staticmethod
  58. def dnld(index: int, command: str, silence: bool = True):
  59. cmd = ld + ' -s {} {}'.format(index, command)
  60. if silence:
  61. os.system(cmd)
  62. return ''
  63. process = os.popen(cmd)
  64. result = process.read()
  65. process.close()
  66. return result
  67. #启动App 指定模拟器必须已经启动
  68. @staticmethod #参数:(模拟器号,点击x,y,点击时间 毫秒)
  69. def run_app(index: int, x: int, y: int, delay: int = 0):
  70. Dnconsole.touch(index, x, y, delay) #点两次,防止漏启动的
  71. Dnconsole.touch(index, x, y, delay)
  72. #输入文字
  73. @staticmethod # 已修复
  74. def input_text(index: int, text: str):
  75. process = os.popen('{} action --index {} --key call.input --value {}'.format(console, index, text))
  76. result = process.read()
  77. process.close()
  78. return result
  79. #启动模拟器
  80. @staticmethod
  81. def launch(index: int, launchtime):
  82. if launchtime > 4:
  83. os.system("start explorer LD_launch\\LD_launch{}.bat".format(index))
  84. time.sleep(launchtime)
  85. #关闭模拟器
  86. @staticmethod
  87. def quit(index: int):
  88. cmd = '{} quit --index {}'.format(console, str(index))
  89. process = os.popen(cmd)
  90. result = process.read()
  91. process.close()
  92. return result
  93. #点击或者长按某点,延时不传数据默认0,设置时间长按
  94. @staticmethod
  95. def image_DIY_xy(index: int, DIY_click, delay: int = 0):
  96. l_x = DIY_click[0] #目标图的左上角坐标x
  97. l_y = DIY_click[1] #左上角坐标y
  98. max_x = DIY_click[2] #点击范围右下角x
  99. max_y = DIY_click[3] # 点击区域右下角y
  100. x_click = random.randint(l_x , max_x) #y轴随机数
  101. y_click = random.randint(l_y , max_y) #y轴随机数
  102. if delay == 0:
  103. Dnconsole.dnld(index, 'input tap {} {}'.format(x_click, y_click))
  104. else:
  105. Dnconsole.dnld(index, 'input swipe {} {} {} {} {}'.format(x_click, y_click,x_click, y_click, delay)) # touch失效
  106. #滑动
  107. @staticmethod
  108. def move_finger(index, start_x, start_y, end_x, end_y, time_min,time_max, delay: int = 0):
  109. click_time = random.randint(time_min, time_max) #随机点击时间随机 100300毫秒
  110. if delay == 1:
  111. Dnconsole.dnld(index, 'input swipe {} {} {} {}'.format(x0, y0, x1, y1))
  112. else:
  113. Dnconsole.dnld(index, 'input swipe {} {} {} {} {}'.format(x0, y0, x1, y1, click_time))
  114. # if __name__ == '__main__':
  115. # Dnconsole.launch(0)# 打开模拟器
  116. # time.sleep(10)# 等待启动
  117. # #: 其他的控制(touch)
  118. # Dnconsole.quit(0)# 退出模拟器
  119. #--------获取正在运行的模拟器标题名称
  120. # runlist = Dnconsole.get_list()
  121. # for i in runlist:
  122. # if i[2] != '0':
  123. # print(i[1])
  124. # # #----------------------------------

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/643260
推荐阅读
相关标签
  

闽ICP备14008679号