Presenting an image in response to specific keyboard presses within a trial

Background: I am new to psychopy. I am trying to create an experiment using the builder. I know how to create routines and loops using Builder. I know I need to use the code component to do what I want to do but have a hard time coming up with the codes (I have no knowledge in python).

What I want to do: Within a trial, I want to present an image feedback when the participant presses specific combination of keys. For instance, image1 will be presented after 4 presses of ‘n’; image2 will be presented after 4 presses of ‘m’. Each trial lasts 6 seconds. The image feedback has to last for 1 second. I don’t want the trial to end after the image feedback, i.e., the participant could potentially get more than one image feedback within a trial.

This is what I have right now on the builder:

I don’t know what to put in the code component to make it work.

Please, can anyone help?

Hi,

In order for us to be able to help you, I suspect it will be necessary for you to explain your task in a bit more detail. For example:

  • What exactly do you mean by “combination of keys”?
  • Do the four presses you mention need to occur in a row?
  • Are ‘n’ and ‘m’ the only keys that could be pressed?

Jan

Thanks. Let me clarify.

  • What exactly do you mean by “combination of keys”?
    Participants are asked to press either ‘n’ or ‘m’ in response to a white box. They can press as many ns or ms as they want. n is linked to foodA, m is linked to foodB. Only one food is available in each trial. Whenever they press a certain number (a pseudo-random number between 5 to 15, with an average of 10) of ns when foodA is available in that trial, they will be presented with an image of foodA. Likewise, whenever they press a certain number of ms when foodB is available in that trial, they will be presented with an image of foodB. After they are presented with 4 images of foodA, they will be probed to eat foodA (image foodA and a message will be shown asking them to eat foodA). Likewise, after they are presented with 4 images of foodB, they will be probed to eat foodB.

  • Do the four presses you mention need to occur in a row?
    No.

  • Are ‘n’ and ‘m’ the only keys that could be pressed?
    Yes

As I am building this task, I resolved some issues but ran into other issues. Now I know how to present the feedback image after a random number of ns or ms presses, but I don’t know how to set the random number to have an average of 10.

I also haven’t figured out how to present the EAT probe after having presented foodA or foodB image for 4 times.

Currently, I have three routines within a loop. The first one presents the white box and record their key responses. The second one is the image feedback. The third one is the EAT probe.

To quickly answer one of your questions: If you want every number to be equally likely, you could draw integers randomly from a uniform distribution, e.g.:

nrPresses = np.random.randint(5,16)  # 15 will be the highest number

Jan

Thanks! I think I just found a way to present the EAT probe correctly. But I ran into another problem. I’ll post it as another topic to make it less confusing.