This seems like a simple problem, but I can’t figure out the issue. I have a dual-task experiment where a video plays on one side of the screen and some text appears on the other side. Participants respond to the text by pressing z, x, c or v. When they respond or when 4 seconds have passed (whichever comes first), the text disappears and new text appears. This continues until the video is over.
I want to record each key that they press throughout this time, and also record if they do not press anything in the 4 seconds. When I choose the option to record all keys in the data tab of my keyboard component, it only records some of the keys. I cannot figure out a pattern for what it does or doesn’t record because each time I run the experiment, it will save a different number of key presses and sometimes it saves repeated keys and other times it does not.
Then I tried to build a code component to save the keys. In the Begin Routine tab, I created a keyboard object called kb and an empty array called allKeysResp. In the Each Frame tab, I had this code:
if currentT >= 4 or kb.getKeys(['z','x','c','v']):
allKeysResp.append(kb.getKeys)
and separately, I tried this code:
keys = kb.getKeys()
if currentT >= 4 or kb.getKeys(['z','x','c','v']):
for key in keys:
print(key.name)
Then in the End Routine I had it write allKeysResp to the data output. However, allKeysResp is just an array of empty arrays (looks like: [ ] [ ] [ ] [ ] [ ] ) with each little array representing a key press. I also tried to append the allKeysResp with kb.key, kb.getKeys[ ], and a number of other iterations of that type of call, but they either gave me the empty arrays or errors.
I found this topic and this topic and this topic that are similar to my issue, but couldn’t seem to apply their solutions to my experiment.
I also need to record the correct response for each of these text appearances. I have the correct response saved in the excel sheet where the text is drawing from, but it is not currently saving that information (even though that box is checked in the data menu for the keyboard component).
As a side note, I would like each key press to appear in it’s own row, rather than an array in a single cell in the excel sheet, if anyone can help me do that. I’ve only been trying to put it in an array for now because that’s all I knew how to do.
Thanks!