0

I am using PsychoPy for an experiment. I have a simple experiment, where the screen changes every time a certain key is pressed. This is simple, and I have used event.waitKeys() for this. However, I would like a 'background' process (not sure of the correct terminology) to be running, where every key press, including key presses that don't trigger the stimuli, or key presses that occur during screen transitions, are recorded.

Is there a way to do this?

user1566200
  • 1,826
  • 4
  • 27
  • 47

1 Answers1

1

Assuming that you've built your experiment using code, the strategy would be to use event.waitKeys() as you do now, but then only have visual action when a certain key is pressed and add other keys to a list. So if your target key is space:

from psychopy import visual, event
win = visual.Window()

for trial in range(5):  # loop over trials. Usually a list of dicts.
    # Prepare and present your stimuli here.
    # Then enter a response-listening phase:
    allResponses = []  # we will fill this in with responses
    while True:
        response = event.waitKeys()   # you probably have event.waitKeys(keyList=['space']) or something like that right now
        allResponses += response  # add keynames. Adds nothing on empty response
        if 'space' in response:
            break  # break out of the while-loop

    # Save trial here along with the contents of allResponses

If you're actively transitioning the content on the screen, you would do this in a for-loop with a call to win.flip() on every iteration rather than the while-loop above. This will discretize the times that you can record responses by the frame rate (usually 60 times per second). If you need finer resolution for e.g. reaction times, use the iohob background where keys are recorded as a separate process, independent on the presentation of stimuli.

Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54