title: detect key press in python, where each iteration can take more than a couple of seconds?
body: <p><strong>Edit:</strong> The below answer to use <strong>keyboard.on_press(callback, suppress=False)</strong> works fine in ubuntu without any issues.
  But in <strong>Redhat/Amazon linux</strong>, it fails to work.</p>
  
  <p>I have used the code snippet from this <a href="https://stackoverflow.com/questions/24072790/detect-key-press-in-python?noredirect=1&amp;lq=1">thread</a></p>
  
  <pre><code>import keyboard  # using module keyboard
  while True:  # making a loop
      try:  # used try so that if user pressed other than the given key error will not be shown
          if keyboard.is_pressed('q'):  # if key 'q' is pressed 
              print('You Pressed A Key!')
              break  # finishing the loop
      except:
          break  # if user pressed a key other than the given key the loop will break
  </code></pre>
  
  <p>But the above code requires the each iteration to be executed in nano-seconds. It fails in the below case:</p>
  
  <pre><code>import keyboard  # using module keyboard
  import time
  while True:  # making a loop
      try:  # used try so that if user pressed other than the given key error will not be shown
          print("sleeping")
          time.sleep(5)
          print("slept")
          if keyboard.is_pressed('q'):  # if key 'q' is pressed 
              print('You Pressed A Key!')
              break  # finishing the loop
      except:
          print("#######")
          break  # if user pressed a key other than the given key the loop will break
  </code></pre>