keyIsPressed: keywords, press the key of true, and false

keyCode: is used to determine which key words, press


keyPressed): the function button is pressed to trigger a



keyIsDown function, a trigger button release (true): the function, press the return key specified, otherwise false

is a comprehensive case, using WSAD and zxcv

 VaR to control the ball movement: x=200; VAR y=200; VAR speed=2; function (setup) {createCanvas (400, 400);} function {background ((draw) 220); ellipse (x, y, 20,20); if (keyIsPressed) {/ / / / continuous trigger with lowercase letters if (key=='a') {x- =speed if (key=='d');} {x+=speed}}; if (keyIsDown (87)) {/ / //87 / / keyCode for triggering w y-=speed;} if (keyIsDown (83)) {/ / //83 / / keyCode for triggering s y+=speed function (keyPressed);}} {/ / when a button is pressed the trigger a / / uppercase letters if (key=='Z') {x-=20}; if (key=='X') {x+=20}}; function (keyReleased) {/ / when the button is loosened, trigger a / / uppercase letters if (key=='C') {y-=20}; if (key=='V') {y+=20}}; 

view effect: the case of

key keyCode

two, and will be in the following Key and keyCode on the screen output you press the button, to write programs can use this way to quickly find the keyCode:

 function (setup) {createCanvas (400, 400);} function {background (draw) (220); textAlign (CENTER); textSize (30) (if; keyIsPressed) {text (key, 200180); text (keyCode, 200220);}}

is the whole content, want to help everyone to learn, I hope you will support a script.

you might be interested in this article:

This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Keyboard interaction in p5.js introductory tutorials | Script Home

You may also be interested in these articles!