I use Pygame 1.9.6 and Python 3.7.4. I want to hold down the space bar and it continuously does the same action over and over. I know how to have have the button get pressed with KEYDOWN
. I looked at the question: How to efficiently hold a key in Pygame? for answers but can't understand the one answer:
while not done:
keys = key.get_pressed()
if keys[K_DOWN]:
print "DOWN"
for e in event.get():
pass # proceed other events.
# always call event.get() or event.poll() in the main loop
I don't get the key.get_pressed()
. It's not from Pygame. Also, I'm assuming it's a function they wrote, but this doesn't show me on when I hold down a 'Key' it continues to run that action and when the 'Key' is released it stops the action being called. Any pointers on how to actually hold down a button or how to make one?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…