'right' key not recognised as correct response

I am building a simple experiment of working memory, where 2 sets of three letters are presented with a distractor between them, and the participant has to answer ‘left’ if one of the letters was present before or ‘right’ if all letters are new.
For this purpose I have an xlsx file with the two sets of letters, the distractor and whether the answer is yes or no, coded with ‘left’ and ‘right’ under the variable corrAns. Everything works smoothly, but for some reason the output only recognises ‘left’ answers as right.
More specifically: when there is a mismatch between the answer given and the correct one, key_target.corr is 0; when the correct answer is ‘left’ and the participant presses ‘left’ key_target.corr is 1; when the correct answer is ‘right’ and the participant presses ‘right’ key_target.corr is 0.
I tried changing the order, adding one more key, but the issue keeps presenting itself.
Any ideas?

Hi @blarosa, if you only have ‘right’ as a key option, does it recognize it as the correct answer when it should? If you swap ‘right’ with ‘space’ for instance, and adjust the correct answer to be ‘space’ in your conditions file, what happens?

@sawal thanks a lot for the suggestion! I just tried replacing ‘right’ with ‘space’ and now it’s able to recognise it as the right answer. Do you have any idea on why that is?

Okay, that was just to make sure it wasn’t something in your conditions file or something and is more specific to the right key.

I’ve attached a working example-- when “2” is presented, the correct answer is “right”, and key_resp.corr returns 1.

Can you test it on your system?

leftRight.psyexp (6.6 KB) conditions.csv (65 Bytes)

With your file it’s able to recognise ‘right’ as the right answer. I had also made a stroop task as practice some time ago and it worked just fine. It’s just this task that has issues.

Two other things I would try is 1. making sure the correct condition files is being called, and 2. check the key_resp.keys variable in the data file, as that records what key was pressed to make sure it’s recording the correct key being pressed.

With this sort of issue, it is worth opening your .csv file in a plain text editor (not in Excel or another spreadsheet). It might be that there is an invisible character that has crept in that you can’t see otherwise (e.g. it might not be 'right' in a cell, but 'right ').

You could instead insert some (temporary) debugging code, e.g. insert a code component from the “custom” component panel, and put something like this in the “end routine” tab:

print('Trial: ' + str(your_loop_name.thisN))
print('|' + corrAns + '|')
print(corrAns == key_target.keys())

You were indeed right! There was a space after ‘right’ in the excel file, I don’t know why I haven’t thought about it.
Thank you so much!

Hi @blarosa, @Michael

I’m having similar issues with ‘right’ key not recognised as correct response. In my conditions file, I recorded right as right without any quotation marks so I’m not sure how to fix this issue.

I looked at the code component to put in the “end routine” tab but I’m not sure what to change aside your_loop_name.

Any advice or recommendations from your end would be much appreciated.

Many thanks and best wishes,


Also change key_target to be whatever the name of your keyboard component is. Then just run the experiment and see what the printed output shows.

Thank you for your advice, @Michael

I made some changes to the code:

print('Trial: ’ + str(Trials.thisN)
print(corrAns == key_resp_2.keys))
print(corrAns == key_resp_2.keys())

However, I’m getting errors in line 2.

Do you have any suggestions?

The number of left and right brackets always need to match (in the first two lines of your code, they don’t). Also you let a curly apostrophe slip in in place of a straight in the first line. e.g:

print('Trial: ' + str(Trials.thisN))
print(corrAns == key_resp_2.keys())
print(corrAns == key_resp_2.keys())

I’m not actually sure if the brackets in key_resp_2.keys() are necessary, or if key_resp_2.keys would suffice.