title: OpenCV: wait for different keys?
body: <p>I am working with OpenCV and I want OpenCV to <em>not</em> wait for <em>any</em> key being pressed (default behaviour of <code>cv2.waitKey()</code>), but to wait for specific keys that I define (and do subsequent actions).</p>
  
  <p>My current solution for this problem is the following recursive one:</p>
  
  <pre><code>def opencv_wait():
      # wait for keypress; capture it
      k = cv2.waitKey(0)
  
      if k == 27:  # this should be ESC
          return   # e.g. end the program
      elif k == some_key:      # some other keys...
          do_some_function()   # ...and actions to do after key is pressed
      else:
          opencv_wait()        # recursively call opencv_wait() for looping
  </code></pre>
  
  <p>My <strong>question</strong> is: is this solution a convenient way to let OpenCV wait for different keys?</p>
  
  <p>Is there a faster / better way to achieve what I want to do?</p>
  
  <p>Basically I want OpenCV to wait (with as little resources wasted as possible) infinitely long until specific keys are pressed that should trigger subsequent actions.</p>