0

I am working with PyGame for the first time, and I haven't been able to find any way to handle event in a non-blocking way. For instance if I am playing a game with a character moving according to key pressing, I want the character to move continuously if I maintain the key pressed, and not having to release the key each time.

I am starting to think it is not possible with PyGame, am I right ?

Thanks.

2
  • I guess almost every tutorial out there explains how to do this. Here's an answer that shows you how to achieve this with an event loop, but you can also search for pygame.key.get_pressed. If you don't know yet how dictionaries work, I can show you a simpler solution than Sloth's. Commented May 13, 2017 at 18:49
  • Take a look at the new answer. Commented May 13, 2017 at 19:15

1 Answer 1

1

Maybe you can use pygame.key.set_repeat() which sends multiple keydown events when you hold down a key; From here: https://www.pygame.org/docs/ref/key.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.