keyIsDown()
Checks whether a certain key is down
Last updated
Checks whether a certain key is down
Last updated
# W keyCode = 87
if keyIsDown(87):
# move square up
# ...
# S keyCode = 83
if keyIsDown(83):
# move square down
# ...
# A keyCode = 65
if keyIsDown(83):
# move square left
# ...
# D keyCode = 68
if keyIsDown(83):
# move square right
# ...def setup():
createCanvas(400,400)
textAlign(CENTER, CENTER)
textSize(20)
squareX = 175
squareY = 100
squareSize = 50
def draw():
global squareX, squareY, squareSize
background("hotpink")
fill(255, 255, 28)
noStroke()
if keyIsDown(87):
squareY += 1
text('"W" is Down(Pressed) now',200,350)
if keyIsDown(83):
squareY -= 1
text('"S" is Down(Pressed) now',200,350)
if keyIsDown(65):
squareX -= 1
text('"A" is Down(Pressed) now',200,350)
if keyIsDown(68):
squareX += 1
text('"D" is Down(Pressed) now',200,350)
stroke('black')
fill (112,88,255)
square(squareX,squareY,squareSize)keyIsDown(VALUE)