psychopy.org | Reference | Downloads | Github

How do I record each key press as a separate event in the output?

Dear all,
I want to be able to let every keypress be represented in output on a separate line. Ideally each line would be an “event”. In the long run I would like such a line to read not only which key was pressed, but also in which trial, latencies (relative to several other events) etc.

For now I am stumped however.

For testing purposes I’ve tried building the following “empty” prototype

empty.psyexp (7.3 KB)
As you can see, I also want the keyboard to listen to “ctrl +z” and then exit. What I’m testing, however, is “space” which I want to be recorded every single time I press the key, as a separate entry.

The output does not conform to what I expect, or want
_empty_2020_Dec_07_1516.csv (178 Bytes)

I think the problem here is that you’re storing the object returned by getKeys rather than the value of that object - resulting in the output you’re seeing. What you need to do is:

keyVal = []
for key in keys:
    keyVal.append(key.name)
thisExp.addData("keys", keyVal)