Adjust the orientation of the bar by keyboard

If this template helps then use it. If not then just delete and start from scratch.

Win10 (e.g. Win10):
**PsychoPy version: ** : 2021.1.4
**Standard Standalone? (y/n): ** YES
What are you trying to achieve?:
Firstly, participants should try to remember the orientation of a bar. After that, they should try to reproduce the angle of the remembered bar by pressing the keyboard. When pressing the right arrow, the bar should rotate clockwise, when pressing the left arrow the bar should rotate anti-clockwise. participants adjust the orientation of the bar until they think its orientation is almost the same with that of the remembered bar, and participants press enter to end this trial.

What did you try to make it work?:
I defined a variable “barorientation” as the orientation of the bar, and use the code:

the following is my routine:

What specifically went wrong when you tried that?:
the bar only rotated for the first press and ended the trial.
untitled.psyexp (12.9 KB)
many thanks if you could help me. I have been puzzled for three days. Looking forward to guidance.

Hi There,

You are close! (maybe you have figured the solution now?) What I suspect you need is in the “begin experiment” tab:

barorientation = 0

Then in the “Each frame” tab:

if res_key.keys == 'right':
    barorientation += 10
elif res_key.keys == 'left':
    barorientation -=10
elif res_keys == 'space':#Assuming you might want to submit the answer with a space?
    continueeRoutine = False

Then use barorientation in the orientation field of your stimulus.

I think you have the right code - just possibly in different tabs!

Hope this helps,

Hi Becca,
Thanks for your suggestion and help. I tried to change my code’s tab as you suggested. But it did not work.

I added the continueRoutine = Ture to the code in the tab of “each frame”, but the outcome is not what I need:
it turn out that once I press the left or right, the bar would rotate endlessly clockwise or anticlockwise, until I press the space.

but what I need is once I press the left or right, the bar only rotate for 10 degrees, and the bat would not disapear until I press the space.

I upload my adjusted program with the excel file, with both of which you can run the psychopy program.

I am looking forward to your help
thanks in advance

untitled.psyexp (13.3 KB)
file.xlsx (9.9 KB)

Hi There,

Ah I see - try this: untitled.psyexp (16.2 KB)

Wow, thank you very much!
Your program suits my experiment requirement definitely. I see you add a loop for the bar. That works well! Thank you again!

Fab! if that worked please can you mark the solution so that future users can easily find it?


Dear @Becca (or of course any other one having an idea how to solve this:-)),

I am using your “methods of adjustment” experiments published on Pavlovia and they have been incredibly helpful with implementing a paradigm that I am currently interested in.

In general, the experiment asks the participants to memorize orientations of stimuli and later reproduce them. I want the participants to reproduce the orientation by rotating a target stimulus of interest until it matched the orientation they have previously remembered. I want to do so by asking them to press the right and left arrow keys on the keyboard and submit their response pressing the space bar. However, I run in the same issue like Liaojiejie described in this thread: the stimulus rotates endlessly.

I already tried to add a “adjustmentLoop” (like suggested in the experiment you posted in this thread) but this did not help. I also moved my code around between tabs, as I thought my problem originates from me having my adjustment code in the “each frame” tab and not in the “end routine” tab like in your example experiment. However, rotating the object only seems to work when I am initialising it in the “each frame” tab. I would be very grateful for any help.

I made this whole thing work using mouse presses, but for the keyboard presses there seems to be a difference that I cannot figure out on my own.
I am adding screenshots of my routine and my adjustmentCode:

Hi There! just to check - are you working off this demo? (which I actually notice has issues with the image stim at the moment but the responses seem ok)


Hi @Becca,

Thank you very much for replying so promptly:-)
I am working with both of your method of adjustment demos, however, the one you linked above is the one I used the most, yes.

In your demo, participants can answer via mouse click, however, I need to use the left and right arrow on the keyboard to adjust the orientation of my image. Unfortunately, switching from mouse to keyboard did not work until now. What do you mean exactly by issues with the image stim, if I may ask?

I am adding a short description of my experiment here, as I want to make more clear what I am trying to achieve:

  1. In my Trials1 component I am intending to show 2 images (of objects) that are rotated. I intend to have one pre-defined rotation for each image in my conditions file (with a total number of 16 different possible orientations). The participant is asked to remember the object and it’s precise orientation here.
  2. Next, in adjustOr1, one of the images is shown again and the participant should use the arrow keys to adjust the image to the orientation he/she remembered before.
    I then intent to save1) the time the participant needed for adjustment, 2) the number he/she pressed each button to adjust the image and 3) the difference between the before shown rotation and the reproduced one (as a measure of accuracy).

Thank you very much for your help. Your demos are super helpful, however, I am struggling a bit to change the coding so that it exactly fits my needs.

Have a lovely day!