Provide feedback for two key presses

OS (Win7):
PsychoPy version (e.g. 1.84.2):
**Standard Standalone

Hello All,
I would like to provide feedback (reaction time) when participant pressed ‘c’ and ‘m’ keys roughly simultaneously using builder, but would like to register that pressing only either key is an error.

I created a routine called feedback for BiGoResp (Keyboard response, storing “all keys”).
In the code property, begin experiment contains

msg=''

Then in the begin routine tab, I put

if BiGoResp.corr and BiGoResp.keys=='c' and BiGoResp.keys=='m':
  msg="RT=%.3f" %(BiGoResp.rt)

else:
   msg="missed!"

This code is obviously not working. Because whichever the key I press, I always get “missed!”. Correct response is defined in an associated excel file specifying [‘c’,‘m’].
I would appreciate if someone can help me solving this problem.

Thank you!

That logic looks a bit weird - the key cannot be "c" and "m"
because they are separate keys.

Are you wanting to see if C and M are pressed at the same time? It’s a little unclear what you are trying to achieve!

Hi Oli,
Thanks for the reply.
Indeed I would like participants to use their both hands pressing two keys (‘c’ and ‘m’) in the context of bimanual or unimanual RT. The feedback for unimanual response is working, but I am struggling with the feedback for the bimanual response.

How can I specify “if response made was matching with the specified corrAns [‘c’,‘m’], and display RT”?

Cheers,
Hakl

I think a problem with this may be that if there is a slight delay between pressing C and M then the participant will end up pressing each between frames which will be read by the if statement as a miss. I’ve got a minimal version working, but that is an issue.

I suspect you might need to use ioHub’s more advanced keyboard functions to check for simultaneous key presses.

Thanks for your reply Michael and Oli.

I thought I would clarify exactly what we want to achieve.
We provide a visual cue which requires a fast as possible bilateral button press on the ‘c’ and ‘m’ buttons (left and right index finger) We don’t necessarily demand that participants press keys exactly simultaneously for the trial to be judged as ‘correct response’; indeed there may be a small asynchrony between hands.

As long as both keys are pressed, then we would like to display the timing of the first key press out of two as feedback of RT, as long as the other key was pressed soon after the first one.

We know that both button presses are being recorded, because both buttons appear as responses in the excel output file. However, we don’t know why the performance feedback code suggests the two buttons have not been pressed.

Am I right to think that we need to use ioHub’s advanced keyboard functions such that if both keys are hit exactly simultaneously, both keypresses are detected and thus the trial is denoted as a successful response?

Thank you!

If the two keys are being detected, then the problem is just the one @Oli noted with the your code. The detected keys variable can’t simultaneously be two different values. It is a list, so you have to test whether it contains both values. e.g.

if BiGoResp.corr and ('c' in BiGoResp.keys and 'm' in BiGoResp.keys):
  msg="RT=%.3f" %(BiGoResp.rt)

else:
   msg="missed!"

But this would take extensive testing to show that it is achieving what you actually want.

Hi Michael,
Thanks for the advice.
Based on your suggestion, we modified the code to

if BiGoResp.corr and ('c' in BiGoResp.keys and 'm' in BiGoResp.keys):
  msg="RT=%.3f" %(BiGoResp.rt[0])

elif BiGoResp.corr and ('m' in BiGoResp.keys and 'c' in BiGoResp.keys):
  msg="RT=%.3f" %(BiGoResp.rt[0])

else:
   msg="missed!"

It is working, except in a situation where ‘m’ key press precedes ‘c’ key press. It seems that this is because the correct answer was set as [‘c’,‘m’] in the excel sheet. If I change it to [‘m’,‘c’], ‘m’ key needs to precede ‘c’ key to display RT.

Is there any way to specify ‘c’ and ‘m’ in any order?

Thanks!

You can change that to:

if ('c' in BiGoResp.keys and corrAns) and  ('m' in BiGoResp.keys and corrAns):
        msg="RT=%.3f" %(BiGoResp.rt[0])
        BiGoResp.corr = True

That way it is checking the list corrAns (or whatever it’s called in your excel file) as well as the keyboard response. It means you’ll also get a correct response too.

BW

Oli

Hi @Oli, that’s a nice way of doing it, although I think the expressions need to be expanded a bit (otherwise we might be ‘anding’ the corrAns list itself rather than checking its contents). Not sure, but something like:

if ('c' in BiGoResp.keys and 'c' in corrAns) and ('m' in BiGoResp.keys and 'm' in corrAns):

Hi Oli and Michael,
Thank you so much for helping us. With your help, I think it’s working now. Only thing I needed to add was to a code testing if any key was pressed. Without that, if the subject doesn’t press anything, the program stops.

In case other people have similar problem, the final codes are:

if (BiGoResp.keys is not None)and ('c' in BiGoResp.keys and 'c' in corrAns) and ('m' in BiGoResp.keys and 'm' in corrAns):
        msg="RT=%.3f" %(BiGoResp.rt[0])
        BiGoResp.corr = True

else:
   msg="missed!"

Thank you both again for your great help. Without your help, we couldn’t start our experiment.
Best wishes,