| Reference | Downloads | Github

RT and key response not recording in data

OS: Windows 10
Psychopy version: 1.85.6

Hi everyone,

I am trying to create my own rating scale instead of using the actual rating scale provided by Psychopy.

I am just going to create an image for the rating scale and have polygons appear over the selected choice.

First I created 3 circle polygons for 3 different choices.
Then I added the key component to correspond to choices ‘1’,‘2’,‘3’.

I am doing this by inserting a code component and then in the ‘Each Routine’ I add

event.getKeys('1'): # if 1 key pushed,
    polygon.opacity = .5
if event.getKeys('2'):
if event.getKeys('3'):

This way if a 1 is pressed a circle appears over the choice corresponding to the ‘1’ key.

In the ‘End Routine’ section I added this:

Exp.addData('reaction_time', key_resp_2.rt). 

However, in the excel file I only see a [] in the “reaction_time” section and the key_resp is blank. Does anyone have any suggestions on how to fix this?

There is no code component tab named that so it is hard to know when this code runs, but I’m guessing it is on every frame. In that case, your code can interfere with any Builder keyboard components. i.e. by calling event.getKeys() you clear the event buffer. That means that a subsequent keyboard component would not register the keypress. Also note that your own code is fighting itself in that regard. e.g. if the subject pushes '2', the first call to event.getKeys(1) will prevent the detection of the '2' except in the vanishingly small chance that that key is pressed between the time of the first and the second event.getKeys()

You should store the results of event.getKeys(), and then cycle through that. e.g.

response = event.getKeys()

if '1' in response:
    # do something 
elif '2' in response:
    # do something else
# etc

You will also need to handle the storing of reaction times and so on, as this code will muck up the keyboard component, by clearing the event buffer.

Alternatively, put the code component beneath the keyboard component, and instead of calling event.getKeys(), query what the keyboard component received. e.g.

if `1` in your_keyboard_component_name.keys():
    # do something 

That way, the keyboard component will still be able to do its job, and store the RT, etc.

1 Like

Sorry I meant ‘Each Frame’

Just used

if `1` in your_keyboard_component_name.keys():

and it works! Thanks!