如何在 PyQT5 中实现关键监听器?即使应用程序处于后台,我也想检测按键。
from PyQt5 import QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
import sys
class Window(QWidget):
...
def keyPressEvent(self, e): # doesnt work when app is in background
if e.key() == Qt.Key_F3:
print(1)
elif e.key() == Qt.Key_F4:
print(0)
...
App = QApplication(sys.argv)
App.setStyle('Fusion')
window = Window()
sys.exit(App.exec())
MM们
相关分类