Keyboard component not recording properly


I’m working on an experiment in which participants will make a choice between four options shown on screen using keys 1-4. I’m trying to record all keypresses by window, but for some reason they’re being recorded in the window after they occur (i.e. keys pressed during window 1 show up in the window 2 row in my output) with negative timestamps.

I’m currently resetting the keyboard clock using kb.clock.reset() right when each screen is presented and then kb.getKeys([‘1’, ‘2’, ‘3’, ‘4’]) at the end of the presentation and I can’t figure out why it isn’t working properly. Any advice would be greatly appreciated!

Hi There,

You might need to set clear=True to clear previous events. It can also be useful to make a basic experiment in Psychopy builder (e.g. a single routine with a keypress) compile it to python and see what the code does there as it will clear the previous events for sure.

Hope this helps,

Hi Becca,

Thanks for the advice! I tried both of your suggestions, but I’m still having issues. I think I could’ve worded my original post better- previous events are being cleared, but all of the responses (and their clearing) are being shifted back in my output file.

For example, if my desired output looks something like this (note that I’m recording keypresses as a (name, response time) tuple:

encoding 1 responses: [(‘1’, 1.0), (‘2’, 2.5)]
encoding 2 responses: [(‘3’, 2.0)]
encoding 3 responses: [(‘4’, 3.5)]

My actual output looks like this:
encoding 1 responses:
encoding 2 responses: [(‘1’, -3.0), (‘2’, -1.5)]
encoding 3 responses: [(‘3’, -2.0)]

The compiled code from a basic keyboard event in the psychopy builder does the same thing I did in this script; any thoughts about what could be going wrong?

Thanks so much,