yuhara327
yuhara327

Reputation: 1

illegal hardware instruction : When pynput and PyQt are combined

I was writing code to automatically click the mouse,

zsh: illegal hardware instruction  /Library/Frameworks/Python.framework/Versions/3.12/bin/python3 

error.
I thought it might be a problem with the combination of Pynput and PyQt, so I added the following code (when a button is clicked, the key pressed afterwards is displayed in the console).
The same error occurred, so I still think the combination is bad.
The screen starts up, but when I press a button, it crashes and throws an error.
The VSCode debugger does not say anything.
The environment is Mac OS Sonoma, Intel Mac.
The following is the source code.

from PyQt6.QtWidgets import QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QPushButton
from pynput import keyboard
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("test")

        grid = QGridLayout()
        self.setLayout(grid)

        self.testbut = QPushButton("テスト")
        self.testbut.clicked.connect(self.function)
        grid.addWidget(self.testbut, 0, 0)
    
    def function(self):
        listener = keyboard.Listener(on_press=self.on_press)
        listener.start()

    def on_press(self, key):
        print(key.char)

qAp = QApplication(sys.argv)
mainwindow = Window()
mainwindow.show()
qAp.exec()

Upvotes: 0

Views: 27

Answers (0)

Related Questions