Pencil Code Reference > keydown
keydown creates a function that will run when a certain key is pressed.
keydown 'w', -> ... ... ...
keydown can be used to execute functions in a script.
In the following script, pressing
pen green, and
pen blue. The turtle moves to wherever the mouse is clicked using
pen red keydown '1', -> pen red keydown '2', -> pen green keydown '3', -> pen blue click (e) -> moveto e↑