檢查 event 是否為 QEvent.KeyPress 即可 from PyQt5.QtCore import QEvent
def eventFilter(self, obj, event): if (event.type() == QtCore.QEvent.KeyPress): key = event.key() if key != Qt.Key_Escape: print("Escape key") return False # will not be filtered out (ie. event will be processed)