V
V
Vlad Zhuravsky2021-09-02 23:12:06
PyQt
Vlad Zhuravsky, 2021-09-02 23:12:06

How to bind QLineEdit to keyboard.write function?

While writing the script, I ran into a problem of linking the QLineEdit function with the keyboard.write function. I'll reformulate my question to make it clearer how to make the text written in QLineEdit appear keyboard.write('here'). I will be extremely happy if someone helps me!)
Here is a simplified version of my code

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
import time
import keyboard

import sys


class Ui_ChatSpamer(QMainWindow):
    def __init__(self):
        super(Ui_ChatSpamer, self).__init__()

    def setupUi(self, ChatSpamer):
        ChatSpamer.setObjectName("ChatSpamer")
        ChatSpamer.setEnabled(True)
        ChatSpamer.resize(500, 430)
        ChatSpamer.setMinimumSize(QtCore.QSize(500, 430))
        ChatSpamer.setMaximumSize(QtCore.QSize(500, 430))
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        ChatSpamer.setFont(font)
        ChatSpamer.setStyleSheet("")

        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(30, 70, 291, 20))
        self.lineEdit.setTabletTracking(False)
        self.lineEdit.setObjectName("lineEdit")

def spammer():
    if keyboard.is_pressed('f7'):

        keyboard.send('t')
        time.sleep(0.6)
        keyboard.write('Тут должен быть текст написанный в QLineEdit', delay=0.02)
        time.sleep(0.6)
        keyboard.send('Enter')
        time.sleep(6)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ChatSpamer = QtWidgets.QMainWindow()
    ui = Ui_ChatSpamer()
    ui.setupUi(ChatSpamer)
    ChatSpamer.show()

    run_inf = QTimer()
    run_inf.setInterval(0)
    run_inf.timeout.connect(spammer)
    run_inf.start()

    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question