I have this simple code, when ESC key pressed PRINTS, however it seems executing "double" times instead of firing one-time only. Python 3.6.2 x86 + PyQt 5.9
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
qApp.installEventFilter(self) #keyboard control
def eventFilter(self, obj, event):
if (event.type() == QtCore.QEvent.KeyPress):
key = event.key()
if key == Qt.Key_Escape:
print("Escape key")
return super(MainWindow, self).eventFilter(obj, event)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())