0

I am running an experimental psychology test in python. In a part of my experiment, I need to rotate a single oriented bar to left or right. I use the following lines of codes to do that.

pygame.event.pump() 

pressed = pygame.key.get_pressed()
BO = randint(0,180)
if pressed[pygame.K_LEFT]:
        BO -= 1
        thisExp.addData('adj_final_ori',BO)


if pressed[pygame.K_RIGHT]:
        BO += 1 
        thisExp.addData('adj_final_ori',BO)

everything works fine, and I can adjust the orientation of the bar when I hold down the Left or Right keys, but the problem is that some times(not always) even after releasing the key the line keeps rotating and I have to push the same key to stop it. Any Idea how to solve this problem?

  • What is BO? What are you tryng to accomplish? – Stqrosta Mar 29 '20 at 13:05
  • BO is the initial orientation of the line that I want to update its orientation by holding down the right or left key. – Mohsen Rafiei Mar 29 '20 at 13:08
  • It is difficult to identify the problem from the sample you've provided. Can you create a [mcve]? I suspect the issue may be resolved if you process events individually, using `pygame.event.get()`. If you want to handle held keys you can use key down and key up events or you can use `pygame.key.set_repeat(..)` to enable repeated key down event generation. – import random Mar 29 '20 at 23:00

0 Answers0