Collecting all key presses while the video is playing

I need to collect all keyboard responses while the video is playing and after it’s finished.

So far the code looks like this:

while mov.status != visual.FINISHED:
        mov.draw()
        win.flip()

  continueRoutine = True
  response = []
  while continueRoutine:
        keys = event.waitKeys()
        response.append(keys)
        if keys[-1] == 'return':
            continueRoutine = False

  response = response[:-1]
  response = [item for sublist in response for item in sublist]
  response = "".join(response)

It works, but it collects only the keypresses that occurred after the video stopped playing. Moving the code for key-press collection into the video while-loop expectedly stops the video from playing. Replacing with getKeys() also breaks the video.

Ideally, I need a solution where I can record RT for the first key press (but I think it should be possible for any solution with clock).

This is a logical flow issue. You want to have getKeys() happen during the movie’s playback loop, and you don’t want to use another while loop because that will just suspend everything until you get a response. Try something like this:

continueRoutine = True
while mov.status != visual.FINISHED:
  mov.draw()
  win.flip()

  response = []
  if continueRoutine: 
        keys = event.getKeys()
        response.append(keys)
        if keys[-1] == 'return':
            continueRoutine = False

response = response[:-1]
response = [item for sublist in response for item in sublist]
response = "".join(response)