title: Trigger Event using key press?
body: <p>I am trying to make my program take 8 pictures only when a key is pressed but I cant find a solution for it. I tried the keyboard package and whenever I would do key is pressed it would throw error. 
  By the way here is my code-</p>
  
  <pre><code>import numpy as np
  import cv2
  import time
  cap = cv2.VideoCapture('morning.mp4')
  
  img_counter = 0
  start_time = time.time()
  x=0
  
  
  while(cap.isOpened()):
      ret, frame = cap.read()
  
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
      cv2.imshow('frame',gray)
      if cv2.waitKey(47) &amp; 0xFF == ord('q'):
          break
      #here is where the image capturing comes into play    
      if time.time() - start_time &gt; 14: #&lt;---- Check if 15 sec passed
          img_name = "frame_{}.png".format(x)
          cv2.imwrite(img_name, frame)
          print("{} written!".format(img_counter))
          start_time = time.time()
          x += 1
      img_counter += 1
      if x == 8:
          break  
  
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>After the comment "#here is where the image capturing comes into play" until the break statement is where   I take pictures of the video and I want to trigger that part of code with a keypress. Any idea how I should go about it?</p>