Skip to content

Commit 7095aa8

Browse files
committed
add runal mouse docs (wip)
1 parent 78db30f commit 7095aa8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

content/runal.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,24 @@ The **console.log** file is deleted upon exit.
474474

475475
### Events
476476

477-
#### onKey(c, key)
478-
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()**.
477+
#### onKey(c, event)
478+
Listen to keyboard events.
479+
480+
Event is an object with 2 attributes:
481+
- **key**: the string representation of the key pressed (`a`, `b`, `c`, `1`, `2`, `3` etc...)
482+
- **code**: the numerical value of the key pressed (97, 98, 99, 49, 50, 51 etc...)
483+
484+
It's a root function, which means it should be placed at the same level as **setup()** and **draw()**.
479485
```js
480486
// mySketch.js
481487
setup(c) { ... }
482488

483489
draw(c) { ... }
484490

485-
onKey(c, key) {
491+
onKey(c, event) {
486492
// save the current canvas in a png file
487493
// when the "c" key is pressed.
488-
if (key == "c") {
494+
if (event.key == "space") {
489495
saveCanvasToPNG("canvas.png");
490496
}
491497
}

0 commit comments

Comments
 (0)