雷电模拟器中控

雷电中控

雷电基本操作(开启,关闭,重启,打开全部,关闭全部,排序,ld.py)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class 操作ld:
def __init__(self, path):
os.putenv("Path", path)

def run_command(self, command):
pipe = subprocess.Popen(args=command, stdout=subprocess.PIPE, shell=True, encoding="gbk")
pipe = pipe.stdout.read()
return pipe

def info_ld(self):
# 获取模拟器信息
return self.run_command('ldconsole.exe list2')

def 启动模拟器(self, num):
self.run_command('ldconsole.exe launch --index ' + str(num))

def 关闭模拟器(self, num):
self.run_command('ldconsole.exe quit --index ' + str(num))

def 重启模拟器(self, num):
self.run_command('ldconsole.exe reboot --index ' + str(num))

def 排列窗口(self):
self.run_command('ldconsole.exe sortWnd')

def 获取指定模拟器信息(self,num):
xx = self.run_command('ldconsole.exe list2')
line = xx.splitlines()
for i in line:
mnqid = i.split(",")[0]
if int(mnqid)==num:
return i
return 0

Qtui固定写法(显示和基本的功能—都得是按钮,main.py)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class TableSignal(QObject):
# 创建一个信号,用于发送表格数据
data_ready = pyqtSignal(list)


class MianWindow(QMainWindow):
def __init__(self):
super(MianWindow, self).__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ld = 操作ld("C:\\leidian\\LDPlayer9") # 这里的地址填雷电模拟器的地址
self.刷新模拟器()


def 刷新模拟器(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.refresh_emulator)
self.timer.start(2000) # 每3秒刷新一次


def refresh_emulator(self): # 这个组件ui里面一定要有
lines = self.ld.info_ld().splitlines()
data = [line.split(',') for line in lines]
self.ui.tableWidget.setRowCount(len(data))
for i, row in enumerate(data):
for j, item in enumerate(row):
self.ui.tableWidget.setItem(i, j, QTableWidgetItem(item))

def open_emulator(self):
num = self.ui.tableWidget.currentRow()
# 打开模拟器时初始化内容
self.ui.tableWidget.setItem(num, 10, QTableWidgetItem("停止中"))
self.ui.tableWidget.setItem(num, 11, QTableWidgetItem("第一个功能"))
self.ui.tableWidget.setItem(num, 12, QTableWidgetItem("未输入"))
self.ld.启动模拟器(num)

def close_emulator(self):
num = self.ui.tableWidget.currentRow()
self.ld.关闭模拟器(num)

def restart_emulator(self):
num = self.ui.tableWidget.currentRow()
self.ld.重启模拟器(num)

def sort_emulator(self):
self.ld.排列窗口()

def open_all_emulator(self):
emu_num = len(self.ld.info_ld().splitlines())
for i in range(emu_num):
self.ld.启动模拟器(i)

def close_all_emulato(self):
emu_num = len(self.ld.info_ld().splitlines())
for i in range(emu_num):
self.ld.关闭模拟器(i)


if __name__ == '__main__':
app = QApplication(sys.argv)
win = MianWindow()
win.show()
sys.exit(app.exec_())

大漠注册固定写法(注册和基本工具—新建一个dm.py)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
class DM:
def __init__(self):
self.dm = None
self.register()

def register(self, reg_code='yonghu84f875b03fb0d5c536a56a631156628a', ver_info='yk4551187'): # 这里填注册码附加码
try:
dirPath = os.path.dirname(__file__)
reg_dm = ctypes.windll.LoadLibrary(dirPath + r'\dmdll\DmReg.dll')
reg_dm.SetDllPathW(dirPath + r'\dmdll\dm.dll', 0)
dm = CreateObject(r'dm.dmsoft')
ret = dm.Reg(reg_code, ver_info)
if ret == 1:
print('[SUCCESS]大漠注册码有效')
self.dm = dm
return dm
elif ret == -2:
print('[ERROR]进程没有以管理员方式运行')
exit(0)
elif ret == -1:
print('[ERROR]无法连接网络')
exit(0)
elif ret == 0:
print('[ERROR]失败,未知错误')
exit(0)
elif ret == 2:
print('[ERROR]余额不足')
exit(0)
elif ret == 3:
print('[ERROR]绑定了本机器,但是账户余额不足50元')
exit(0)
elif ret == 4:
print('[ERROR]注册码错误')
exit(0)
elif ret == 5:
print('[ERROR]你的机器或者IP在黑名单列表中或者不在白名单列表中')
exit(0)
elif ret == 777:
print(
'[ERROR]同一个机器码注册次数超过了服务器限制,被暂时封禁. 请登录后台,插件今日详细消费记录里,相应的机器码是否有次数异常,并立刻优化解决.如果还有问题,可以联系我来解决.')
exit(0)
else:
print('[ERROR]', ret)
exit(0)
except Exception as e:
print(e)
exit(1)

def Version(self):
print(self.dm.Ver())

def newDM(self):
return CreateObject(r'dm.dmsoft')




class DMutil:
def __init__(self, dm):
self.dm = dm


def 找图(self, x1, y1, x2, y2, picName, dataColor="505050", sim=0.9, dir=0):
pic_ret = self.dm.FindPicE(x1, y1, x2, y2, picName, dataColor, sim, dir)
if pic_ret != '-1|-1|-1':
items = pic_ret.split("|")
print("找到图片信息--->", items)
return [int(items[1]), int(items[2])]
else:
print("定位不到图片", pic_ret, picName)
return [None, None]

def 找图成功点击(self, x1, y1, x2, y2, picName, dataColor="505050", sim=0.9, dir=0):
res = self.findPic(x1, y1, x2, y2, picName, dataColor, sim, dir)
if res[0] and res[1]:
self.dm.移动鼠标(res[0], res[1])
self.dm.LeftClick()
print("点击成功---->", res)
return 1
return 0

def 找图直到成功点击(self, x1, y1, x2, y2, picName, 偏移x=0, 偏移y=0, 延迟=0, dataColor="505050", sim=0.9, dir=0):
while True:
res = self.findPic(x1, y1, x2, y2, picName, dataColor, sim, dir)
if res[0] and res[1]:
res[0] = res[0] + int(偏移x)
res[1] = res[1] + int(偏移y)
self.移动鼠标(res[0], res[1])
self.dm.LeftClick()
print("点击成功---->", res, picName)
time.sleep(延迟)
return 1
else:
print("没找到---", res, picName)


def 多图直到成功点击(self, 数组, 偏移x=0, 偏移y=0, 延迟=0, dataColor="505050", sim=0.9, dir=0):
while True:
for item in 数组:
x1, y1, x2, y2, picName = item # 解包元组
res = self.findPic(x1, y1, x2, y2, picName, dataColor, sim, dir)
if res[0] and res[1]:
res[0] = res[0] + int(偏移x)
res[1] = res[1] + int(偏移y)
self.移动鼠标(res[0], res[1])
self.dm.LeftClick()
print("点击成功---->", res, picName)
time.sleep(延迟)
return 1
else:
print("没找到---", res, picName)


def 找图偏移点击(self, x1, y1, x2, y2, picName, 偏移x, 偏移y, 延迟=0, dataColor="505050", sim=0.9, dir=0):
res = self.findPic(x1, y1, x2, y2, picName, dataColor, sim, dir)
if res[0] and res[1]:
self.移动鼠标(res[0] + int(偏移x), res[1] + int(偏移y))
print(res[0] + int(偏移x), res[1] + int(偏移y))
self.dm.LeftClick()
print("点击成功---->", res)
time.sleep(延迟)
return 1
else:
return 0



def 多图偏移点击Ex(self, 数组, 偏移x, 偏移y, 延迟=0, dataColor="505050", sim=0.9, dir=0):
for item in 数组:
x1, y1, x2, y2, picName = item # 解包元组
res = self.findPic(x1, y1, x2, y2, picName, dataColor, sim, dir)
if res[0] and res[1]:
self.移动鼠标(res[0] + int(偏移x), res[1] + int(偏移y))
print(res[0] + int(偏移x), res[1] + int(偏移y))
self.dm.LeftClick()
print("点击成功---->", res)
time.sleep(延迟)
return 1
return 0



def 移动鼠标(self, x, y, 随机=True):
if 随机 == True:
self.dm.MoveTo(x, y)
else:
self.dm.MoveTo(x + random.randint(1, 5), y + random.randint(1, 5))



def 点击(self, x, y):
self.移动鼠标(x, y)
self.dm.LeftClick()

def 按住(self, x, y, yc_time):
self.移动鼠标(x, y)
self.dm.LeftDown()
time.sleep(yc_time)
self.dm.LeftUp()

def 滑动(self, x1, y1, x2, y2):
self.移动鼠标(x1, y1)
self.dm.LeftDown()
time.sleep(0.5)
self.移动鼠标(x2, y2)
time.sleep(0.5)
self.dm.LeftUp()
time.sleep(0.5)



def 截图(self, x1, y1, x2, y2, file):
self.dm.Capture(x1, y1, x2, y2, file)

中控多线程(gthread.py)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Login:
def __init__(self, dm):
self.dm = dm
self.pic = DMutil(self.dm)

def start(self):
pass




class Gthread(QThread):
def __init__(self, dm, ini, name=None):
super(QThread, self).__init__()
self.dm = dm
self.ini = ini
self.dm.SetPath(os.getcwd() + "/images")

def run(self):
items = self.ini.split(" ")
for item in items:
if "任务一" == item:
login = Login(self.dm)
login.start()
elif item == "任务二":
任务二 = 任务二()
任务二.start()
time.sleep(1)

开启线程(main.py)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class MianWindow(QMainWindow):
def __init__(self):
super(MianWindow, self).__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ld = 操作ld("C:\\leidian\\LDPlayer9")
self.刷新模拟器()
self.dm = DM()
self.util = DMutil(self.dm)
self.大漠集 = {}
self.线程集 = {}



def start_task(self):
当前行 = self.ui.tableWidget.currentRow()
当前句柄 = int(self.ui.tableWidget.item(当前行, 3).text())
线程状态 = self.ui.tableWidget.item(当前行, 10).text()
当前任务 = self.ui.tableWidget.item(当前行, 11).text()
if 线程状态 == "停止中":
大漠 = self.大漠集.get(当前行, None)
if 大漠:
# 之前启动过,直接拿原来的句柄
绑定ret = 大漠.BindWindowEx(当前句柄, "gdi", "windows3", "windows", "", 0)
if 绑定ret == 1:
print("窗口绑定成功")
# 获取对应多线程并开启
主任务线程变量 = self.线程集.get(当前行, None)
if 主任务线程变量:
主任务线程变量.start()
print("重启成功")
else:
print("获取线程失败")
self.ui.tableWidget.setItem(当前行, 10, QTableWidgetItem("运行中"))
elif 绑定ret == 0:
print("窗口绑定失败")
else:
new_dm = self.dm.newDM()
self.大漠集[当前行] = new_dm
绑定ret = new_dm.BindWindowEx(当前句柄, "gdi", "windows3", "windows", "", 0)
if 绑定ret == 1:
print("窗口绑定成功")
# 开启多线程并保存
主任务线程变量 = 主任务线程(new_dm, 当前任务)
主任务线程变量.start()

self.线程集[当前行] = 主任务线程变量

self.ui.tableWidget.setItem(当前行, 10, QTableWidgetItem("运行中"))
elif 绑定ret == 0:
print("窗口绑定失败")



def pause_task(self):
try:
当前行 = self.ui.tableWidget.currentRow()
当前句柄 = int(self.ui.tableWidget.item(当前行, 3).text())
线程状态 = self.ui.tableWidget.item(当前行, 10).text()
if 线程状态 == "运行中":
大漠 = self.大漠集[当前行]
解绑ret = 大漠.UnBindWindow()
if 解绑ret == 1:
print("窗口解绑成功")
当前线程 = self.线程集.get(当前行, None)
if 当前线程 != None:
当前线程.terminate()
print("暂停线程成功", 当前行)
self.ui.tableWidget.setItem(当前行, 10, QTableWidgetItem("停止中"))
else:
print("窗口解绑失败")
else:
print("未启动")

except Exception as e:
print(e)

模板ui样式

基本样式

打包插件命令

1
cxFreeze --script main.py --target-dir=outDefault --base-name=win32gui