后台点击代码无法实现点击效果
class Thread_1(QThread): # 线程1
def __init__(self):
super().__init__()
def run(self):
AccountLogin.begin()
class CUi_MainWindow(QMainWindow, Ui_MainWindow): # 继承于UI父类
def __init__(self, parent=None):
super(CUi_MainWindow, self).__init__(parent)
self.setupUi(self)
self.init_login_info()
self.pushButton.clicked.connect(self.start)
self.pushButton_2.clicked.connect(self.pause)
def save(self):
settings = QSettings("config.ini", QSettings.IniFormat)
settings.setValue("excl_path", self.lineEdit.text())
settings.setValue("share_path", self.lineEdit_2.text())
settings.setValue("ld_path", self.lineEdit_3.text())
settings.setValue("thread", self.comboBox.currentIndex())
settings.setValue("table", self.comboBox_2.currentIndex())
def init_login_info(self):
settings = QSettings("config.ini", QSettings.IniFormat)
ld_path = settings.value("ld_path")
share_path = settings.value("share_path")
excl_path = settings.value("excl_path")
thread = settings.value("thread")
table = settings.value("table")
pause = settings.value("pause")
if str(pause) == "恢复":
self.pushButton_2.setText("暂停")
elif str(pause) == "暂停":
settings.setValue("pause", "恢复")
self.pushButton_2.setText("暂停")
self.lineEdit.setText(excl_path)
self.lineEdit_2.setText(share_path)
self.lineEdit_3.setText(ld_path)
self.comboBox_2.setCurrentIndex(int(table))
self.comboBox.setCurrentIndex(int(thread))
def start(self):
self.save()
self.thread_1 = Thread_1() # 创建线程
self.thread_1.start() # 开始线程
——————————————————————————————————
def doClick(bind, cx, cy): # 点击坐标
AccountLogin.lock.acquire()
long_position = win32api.MAKELONG(cx, cy) # 模拟鼠标指针 传送到指定坐标
win32api.SendMessage(bind, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position) # 模拟鼠标按下
sleep(0.1)
win32api.SendMessage(bind, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position) # 模拟鼠标弹起
sleep(0.5)
AccountLogin.lock.release()
print('点击', bind, cx, cy, '坐标')
想做一个雷电模拟器账号登录的脚本,其中有一段利用win32实现后台点击的代码,独立运行的情况下,一切都正常,但是一旦通过PYQT运行主程序,该代码段依然能跑通,但是无法实现点击效果。系统也没有报错,检查过所有的参数都是正确的。整个主程序能全部跑通,系统无报错,界面点击事件也是正常的。