Skip to content
Sign upLog in
← Back to Community

Onkeypress

Profile icon
RaptorFace

does turtle not have onkeypress? Because I tried it on another repl and it worked fine

Voters
Profile icon
RaptorFace
Comments
hotnewtop
Profile icon
Nipunn

when you create the function you need put x,y in the brackets e.g. def left(x,y):

Profile icon
InvisibleOne
Profile icon
RaptorFace

Thanks guys but it is still not working...

Profile icon
RYANTADIPARTHI

@bohandong
hmm, maybe it's a bug then. maybe report it. cause it should work

Profile icon
RYANTADIPARTHI

@bohandong
or maybe for the functions, do left or right instead

like this:

def right(): c.right(90) c.onkey(right, 'd')

like that.

Profile icon
RaptorFace

@RYANTADIPARTHI
Yeah I think it is a bug! Thanks for helping though!

Profile icon
RYANTADIPARTHI
Profile icon
RYANTADIPARTHI

Solution

Nope, it's not onkeypress in repl.it, you have to use onkey. like this.

c.onkey(up, "w") c.onkey(down, "s") c.onkey(right, "d") c.onkey(left, "a") c.listen() # you don't need this c.done()

you don't exactly need the c.listen() put your code like this:

c.onkey(up, "w") c.onkey(down, "s") c.onkey(right, "d") c.onkey(left, "a")

so that's the legitimate thing. that will work. it's not onkeypress it's just onkey
That should work

Profile icon
InvisibleOne

I think it should be:

c.onkey(up, "w") c.onkey(down, "s") #so on