title: PyQt5 - Double press same keyboard key
body: <p>I am handling multiple key presses by subclassing <code>QMainWindow</code> and overriding the <code>keyPressEvent</code> and <code>keyReleaseEvent</code> functions, and then updating a dictionary if the key is down or not...</p>
  
  <pre class="lang-py prettyprint-override"><code>  def keyPressEvent(self,event):
      self.pressedKeys[event.key()] = True
  
    def keyReleaseEvent(self,event):
      self.pressedKeys[event.key()] = False
  </code></pre>
  
  <p>... and the <code>pressedKeysArray</code> being:</p>
  
  <pre class="lang-py prettyprint-override"><code>  pressedKeys = {Qt.Key_Left: False,
                   Qt.Key_Right: False,
                   Qt.Key_Down: False,
                   Qt.Key_Up: False}
  </code></pre>
  
  <p>However, I would like to be able to catch a double right arrow click, say within 100 or 200 milliseconds of each other. I would expand the <code>pressedKeys</code> dictionary to include double clicked keys that can be set to <code>True</code> or <code>False</code>, but I don't know how to know if the key has been pressed twice in quick succession.</p>
  
  <p>Here is my code so far:</p>
  
  <pre class="lang-py prettyprint-override"><code>from PyQt5.QtCore import *
  from PyQt5.QtGui import *
  from PyQt5.QtWidgets import *
  import sys
  
  class MainWindow(QMainWindow):
    pressedKeys = {Qt.Key_Left: False,
                   Qt.Key_Right: False,
                   Qt.Key_Down: False,
                   Qt.Key_Up: False}
  
    def __init__(self,parent=None,*args,**kwargs):
      QMainWindow.__init__(self,parent,*args,**kwargs)
      self.parent = parent
  
      self.timer = QTimer()
      self.timer.timeout.connect(self.keyAction)
      self.timer.start(50)
  
      self.show()
  
    def keyPressEvent(self,event):
      self.pressedKeys[event.key()] = True
  
    def keyReleaseEvent(self,event):
      self.pressedKeys[event.key()] = False
  
    def keyAction(self):
      if self.pressedKeys[Qt.Key_Left] and self.pressedKeys[Qt.Key_Down]: print("rolling left")
  
      elif self.pressedKeys[Qt.Key_Right] and self.pressedKeys[Qt.Key_Down]: print("rolling right")
  
      elif self.pressedKeys[Qt.Key_Left]: print("running left")
  
      elif self.pressedKeys[Qt.Key_Right]: print("running right")
  
      elif self.pressedKeys[Qt.Key_Down]: print("crouching") #return here to block effect of 'up' key being pressed
  
      if self.pressedKeys[Qt.Key_Up]: print("jumping")
  
  def exceptHook(exectype,value,traceback):
    sys.__excepthook__(exectype,value,traceback)
  
  if __name__ == "__main__":
    sys.excepthook = exceptHook
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    app.quit()
  </code></pre>