While playing around with Python's Turtle module, I used some key events as the official documentation states:
turtle.onkey(fun, key)
Parameters:
fun
– a function with no arguments or Nonekey
– a string: key (e.g. “a”) or key-symbol (e.g. “space”)
Now the interesting thing is that when you call 1) the onkeyrelease()
method and pass a not registered string (like an empty one (""
), or "+"
, etc.) as key
parameter:
turtle.onkeyrelease(lambda: print("Got key event while listening to none."), "")
No matter what key is pressed by the user, the program outputs "Got key event ...
", which was by the way the problem in this question.
Unfortunately I can't find more information about this behavior in the documentation ore elsewhere on the internet. So I wonder if there is a complete list of all supported key-name-strings used to program key events?
1) The basic setup used in the question:
import turtle
turtle.setup(700,500)
turtleWindow = turtle.Screen()
turtleWindow.onkey(lambda: print("You pressed 'a'"), "a")
turtleWindow.listen()