Skip to content

Commit c6d66c1

Browse files
authored
Merge pull request #3050 from bomoko/documentation/KeyIsDown_improvement
Adds numeric keyCode example to keyIsDown docs
2 parents a41d3f1 + 6b35b3c commit c6d66c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/events/keyboard.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,33 @@ p5.prototype._onblur = function(e) {
350350
* }
351351
* </code></div>
352352
*
353+
* <div><code>
354+
* var diameter = 50;
355+
*
356+
* function setup() {
357+
* createCanvas(512, 512);
358+
* }
359+
*
360+
* function draw() {
361+
* // 107 and 187 are keyCodes for "+"
362+
* if (keyIsDown(107) || keyIsDown(187)) {
363+
* diameter += 1;
364+
* }
365+
*
366+
* // 109 and 189 are keyCodes for "-"
367+
* if (keyIsDown(109) || keyIsDown(189)) {
368+
* diameter -= 1;
369+
* }
370+
*
371+
* clear();
372+
* fill(255, 0, 0);
373+
* ellipse(50, 50, diameter, diameter);
374+
* }
375+
* </code></div>
376+
*
353377
* @alt
354378
* 50x50 red ellipse moves left, right, up and down with arrow presses.
379+
* 50x50 red ellipse gets bigger or smaller when + or - are pressed.
355380
*
356381
*/
357382
p5.prototype.keyIsDown = function(code) {

0 commit comments

Comments
 (0)