某游戏平台及自动登录功能
以下原代码为本人原创,仅供交流使用,不做任何其他功能,如作他用后果自负
import time
from os import getcwd
from xunlu1_1 import ImgPro, KeyBord
from subprocess import Popen
USER = '123456789'
PASSWOED = '......'
WeGame_path = 'E:\Program Files (x86)\WeGame\wegame.exe'
class DengLu():
def __init__(self, WeGame_path, opt='DNF'):
self.WeGame_path = WeGame_path
self.g = ImgPro()
self.key = KeyBord()
self.g.play_name = "WeGame"
self.J_PATH = getcwd() + '/'
self.opt = opt
def __del__(self):
print('模拟键盘关闭')
self.key.close()
def open_wegame(self, We=None):
if We is None:
Popen(self.WeGame_path)
for i in range(10):
time.sleep(0.5)
if self.g.get_handle():
self.g.set_window()
return True
print("打开界面失败")
def __shuru(self):
for i in range(10):
time.sleep(0.5)
try:
log_gin = self.g.temp_late(self.J_PATH + 'img_page/denglu_img/01.png', xishu=0.85)
if log_gin:
self.key.click_left(log_gin[0] + 100, log_gin[1] + 186)
for i in range(13):
self.key.down_up("backspace")
self.key.down_up(USER)
self.key.click_left(log_gin[0] + 100, log_gin[1] + 222)
time.sleep(1)
self.key.down_up(PASSWOED)
self.key.click_left(log_gin[0] + 100, log_gin[1] + 320)
print('输入账号登录成功')
return True
except:
print('输入账号错误次数:', i)
print("输入账号失败...")
def __opt_game(self):
row = 200
if self.opt == 'LOL':
row = row + 50
for i in range(10):
time.sleep(0.5)
try:
if not self.open_wegame(We=True):
break
log_gin = self.g.temp_late(self.J_PATH + 'img_page/denglu_img/02.png', xishu=0.85)
if log_gin:
self.key.click_left(log_gin[0] + 350, log_gin[1])
time.sleep(0.8)
self.key.click_left(log_gin[0] + 30, log_gin[1] + row)
time.sleep(1)
print("WeGame选择游戏成功")
return True
except:
print('WeGame登录错误次数:', i)
print("选择游戏错误")
def __qidong(self):
for i in range(10):
time.sleep(0.5)
try:
log_gin = self.g.temp_late(self.J_PATH + 'img_page/denglu_img/03.png', xishu=0.85)
if log_gin:
self.key.click_left(log_gin)
print("登录中")
return True
except:
print('识别启动失败次数:', i)
print("启动游戏点击失败")
def __is_login(self):
self.g.play_name = '地下城与勇士'
st1 = time.time()
while True:
time.sleep(1)
if time.time() - st1 > 60:
print('登录超时....')
return
if self.g.get_handle():
print("运行DNF成功")
return True
def opt_hero(self):
if self.__is_login():
for i in range(31):
time.sleep(2)
print('登陆中', i)
try:
log_gin = self.g.temp_late(self.J_PATH + 'img_page/denglu_img/04.png', xishu=0.93)
if log_gin:
try:
self.g.set_window()
except:
continue
self.key.click_left(log_gin)
print("选择常用角色")
time.sleep(1)
self.key.click_left(log_gin)
time.sleep(3)
self.key.down_up('esc')
return True
except:
print('识别选择角色失败次数:', i)
print("选择角色失败")
def run_denglu(self):
if self.open_wegame():
self.__shuru()
if self.__opt_game():
self.__qidong()
self.opt_hero()
def run_chongqi(self):
self.open_wegame()
if self.__opt_game():
pass
self.__qidong()
self.opt_hero()
def Wegame_denglu(self):
if self.open_wegame():
self.__shuru()
self.__opt_game()
if __name__ == '__main__':
o = DengLu(WeGame_path)
其中的ImgPro, KeyBord为自己封装的图片处理识别,键盘模拟库
|