P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  • Example
  • Syntax
  • Description
  1. Reference
  2. Events
  3. Keyboard

keyReleased()

PreviouskeyPressed()NextMouse

Last updated 2 years ago

Example

def keyReleased():
  ...
  text(key,width/2,0.2*height)

Syntax

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

  fill(255, 164, 28)
  stroke(44, 129, 237)
  strokeWeight(2)
  
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

Description

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

Like and 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.

Built-in variables like and 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 !

We'd love to hear your Feedback/Comments .

draw()
setup()
Strivemath
here
keyCode
key