psychopy.org | Reference | Downloads | Github

Triggers based on key responses

If this template helps then use it. If not then just delete and start from scratch.

OS - Windows 7
PsychoPy version - 1.9:

What are you trying to achieve?:
I would like triggers to be sent whenever a participant response.
My allocated keys for responses are left and down

What did you try to make it work?:
I added a code component and at the Begin Experiment tab I added:
codeTable = {“down”:11, “left”:12} ,

Then I added an I/O and in the start data section i added codeTable[key_resp_2.keys], but it doesnt work.

I also tried codeTable[key_resp_2.keys[0]] but it did not work.

What specifically went wrong when you tried that?:
The error I received was the following:

win.calOnFlip(p_port_4.setData,int(codeTable[key_resp_2.keys]))

TypeError: unhashable type: ‘list’

.keys() returns a list, even if there is just one key press. Try key_resp_2.keys[0] to extract the actual key press from the list.

Thank you for your response Michael.

I tried it but unfortunately it has the following error:

IndexError:list index out of range

That likely indicates the list is empty. i.e. there is no zeroth item in []. You need to check there actually was a response before you try to do things with it.