Skip to content

Commit 9d69be5

Browse files
author
Xavier Godart
committed
add events docs to runal
1 parent a7b6b2b commit 9d69be5

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

content/runal.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,23 @@ tail -f console.log
467467

468468
The **console.log** file is deleted upon exit.
469469

470+
### Events
471+
472+
#### onKey(c, key)
473+
Listen to keyboard events. Key contains the key string. **It's a root function, which means it should be placed at the same level as **setup()** and **draw()**.
474+
```js
475+
// mySketch.js
476+
setup(c) { ... }
477+
478+
draw(c) { ... }
479+
480+
onKey(c, key) {
481+
// save the current canvas in a png file
482+
// when the "c" key is pressed.
483+
if (key == "c") {
484+
saveCanvasToPNG("canvas.png");
485+
}
486+
}
487+
```
488+
470489
</section>

0 commit comments

Comments
 (0)