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 1 runs pen red, 2 runs pen green, and 3 runs pen blue. The turtle moves to wherever the mouse is clicked using click.
pen red keydown '1', -> pen red keydown '2', -> pen green keydown '3', -> pen blue click (e) -> moveto e↑