title: Python Key press and Key Release Listener
body: <p>I am controlling a remote toy car using python code. As of now, the code is as below:</p>
  <pre><code>def getkey():
          fd = sys.stdin.fileno()
          old = termios.tcgetattr(fd)
          new = termios.tcgetattr(fd)
          new[3] = new[3] &amp; ~TERMIOS.ICANON &amp; ~TERMIOS.ECHO
          new[6][TERMIOS.VMIN] = 1
          new[6][TERMIOS.VTIME] = 0
          termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
          c = None
          try:
                  c = os.read(fd, 1)
          finally:
                  termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
          return c
  
  def car():
      while True:
          key = getkey()
          if key == 's': #Down arrow
              print &quot;Down&quot;
              Backward()
          elif key == 'w': #Up arrow
              print &quot;Up&quot;
              forward()
          elif key == 'a': 
              print &quot;left&quot;
              Left()
          elif key == 'd': 
              print &quot;Right&quot;
              Right()
          elif key == 'q': #Quit
              print &quot;That's It&quot;
              break
  def forward():
      GPIO.output(11,True)  #Move forward
  </code></pre>
  <p>When I press 'w' <code>forward()</code> method is called and the car moves forward but wont stop until I quit the program or call <code>GPIO.output(11, False)</code> from some other method.</p>
  <p>Is there any key Listener which detects the key release of any particular key?</p>
  <p>For example, if 'w' pressed called this method and if released call some other method</p>
  <p>Sudo code:</p>
  <pre><code>if w_isPressed()
     forward()
  else if w_isReleased()
      stop()
  </code></pre>