Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Last active December 24, 2015 09:19
Show Gist options
  • Save uranusjr/6775945 to your computer and use it in GitHub Desktop.
Save uranusjr/6775945 to your computer and use it in GitHub Desktop.
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class KeyListener(QObject):
def eventFilter(self, obj, event):
if event.type() == QEvent.KeyPress:
if event.key() == Qt.Key_Control:
print('Control pressed')
elif event.type() == QEvent.KeyRelease:
if event.key() == Qt.Key_Control:
print('Control released')
return False
class Window(QMainWindow):
def keyPressEvent(self, e):
if e.key() == Qt.Key_O and e.modifiers() & Qt.ControlModifier:
print('Control+O pressed')
return super(Window, self).keyPressEvent(e)
def main():
listener = KeyListener()
app = QApplication(sys.argv)
app.installEventFilter(listener)
win = Window()
win.show()
app.exec_()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment