def keyReleased():


def keyReleased():
    # execute this code when any key is released
Full Code Example
def setup():
  createCanvas(300, 300)

  fill(255, 164, 28)
  stroke(44, 129, 237)
w = 150
h = 150

def draw():
  background(255, 79, 132)
  ellipse(150, 150, w, h)

def keyReleased():
  global w, h
  if keyCode == 37:
    w -= 30
  elif keyCode == 38:
    h += 30
  elif keyCode == 39:
    w += 30
  elif keyCode == 40:
    h -= 30ython


Like draw() and setup() functions, this function is a built-in function that we override. That is, it knows when to run, but it doesn't know what do? That's why in the syntax, we just seem to define it, but not call it later.

So, this function runs when a key is released (regardless if you were holding it or you just pressed it before that).

Built-in variables like keyCode and key can be used to know which key was released.

Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!

We'd love to hear your Feedback/Comments here.

Last updated