0

So I have a turtle that moves left when 'a' is pressed.

def turtle_left():
    turtle.forward(-1)

turtle.listen()
turtle.onkeypress(turtle_left, 'a')

However, if I wanted another movement, for example pressing 'w' makes it move up, then it stops the turtle moving left. So what I'm asking is, can I have 2 keys being held at once to move the turtle, if possible I'd like to keep it in the turtle library - but maybe there is another key library that can help with this better.

Thank you!

rpanai
  • 12,515
  • 2
  • 42
  • 64
user9888447
  • 127
  • 1
  • 9

1 Answers1

0

Yes, you can do that without using any external library. I think this post is very similar to the given below.

How to bind several key presses together in turtle graphics?

You can make an array of events and then process it on the basis of total events in the list.

Ankit Agrawal
  • 596
  • 5
  • 12
  • Thank you, I used the test code and that seems to work. I'll edit that to fit with my code :) – user9888447 Feb 20 '19 at 19:14
  • It does indeed look similar to the question you linked to. In which case you should flag this as a duplicate of that one, rather than simply post a link to another question as an answer. – SiHa Feb 20 '19 at 19:17