Exhibiting a component after keypress

Hi, I need help to create a little piece of code for an online experiment on Pavlovia. I need that an image component starts the routine hidded and be only exibited after a keypress. I also need that the keypress event be recorded (including rt). Is that possible? Could you help me?

Could you simply use the keypress to end one routine and have the next routine will all the same displays plus the image?

It is also very doable with code within a single routine.

Not actually. It needs to be in a single routine, because the same stimuli is presented after the reponse to the first question (recognition). The stimuli is fully randomized (by code) and since there is a second question (confidence) to the same stimuli in the same loop, the propsed solution would not be viable.

The code solution involves changing the opacity (0 to 1) or the location (off screen to on screen) or the image itself (transparent rectangle to target) in Each Frame code.

For example

keys = event.getKeys()
if “space” in keys:
     image_1.setOpacity(1)

Thanks, it’s a nice solution and worked well. But I also need that these keypress and it’s response times are also recorded when running on Pavlovia. How can I get this?

You can use thisExp.addData(‘RT’,t) for the reaction time though further key presses will overwrite it unless you set and check a flag.

Do you want any key to be accepted? If so you can use if len(keys) and then save keys[0]

Thanks a lot