How to restrict the sequence of key press

Hi, thank you for taking your time to read my post. I am a beginner in Psychopy and I don’t have any knowledge in python. I would be very grateful if you could help me. :cry:

OS (e.g. Win10): Mac OS 10.14.6
PsychoPy version (e.g. 1.84.x): 2021.2.3
Standard Standalone? (y/n) : Yes
**What are you trying to achieve?: I used Builder to compile an experiment in which the participant should press the button “r” to start, “space” to end, and “down” to turn to the next page in each routine. When pressing the buttons “r” and “space”, a notification sound would be played.
My questions are: 1. how to restrict the sequence of the keys in the order of “r” > “space” > “down”? Since I compile hundreds of these similar tasks (let’s call it task 1), I’m afraid that the participant may get bored and don’t follow the sequence or miss some key presses, which may cause them directly skip to the next task and cannot redo the previous one (the procedure of the tasks is in one-way, no return).
2. In the design of my experiment, there is another type of task (memory test) intervened between the task (task 1) I mentioned in question 1. There is a key response used in the memory test, but different from the keys used in the previous task. Sometimes I noticed that when I pressed “r” or “space” by accident in the memory test, the notification sound would be played in the first routine of the next session/loop of task 1. How can I restrict the key responses within their own routine?
3. The screenshot (comman+3) cannot be used when the experiment is running.
By the way, the command used in the sound component is "start > condition > $event.getKeys(‘r’) and $event.getKeys(‘space’).

I know to solve the question, the coder component would be used, but I don’t know how and what commands to write in the coder. Please help me, thanks a lot.

Sorry for my poor English if my description isn’t clear enough.


this is task 1

this is the starting page of the memory test

this is the memory test

this is the focus point followed after the memory test

Hi there, to restrict sequence you want 3 routines where each routine has one keyboard component where the allowed key in each keyboard component is the current key in the sequence i.e. “r” in routine 1, “space” in routine 2 and “down” in routine 3.

Becca

Thank you very much Becca. Sorry I forgot to mention one thing previously. Keys ‘r’ and ‘space’ each corresponds with a sound feedback (two different sound files in total) which reminds the participant that the key is pressed. Just now I tried your solution. It did restrict the sequence, but the sound feedback didn’t work. I think it is because ‘force end of routine’ and ‘play sound’ were triggered at the same time so that the sound wouldn’t be played. So I think it would be better to restrict the sequence of key presses within a single routine. Anyway, thank you very much for your help. :smiling_face_with_three_hearts:

I think I just figured out how to solve ‘play sound’ and ‘force end of routine’ on the basis of your suggestion! Thank you VERY MUCH :smiling_face_with_three_hearts:

1 Like