# keyReleased()

## Example

<figure><img src="https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2FN73tpKYxlea6zJDD88vr%2FmySketch%20(3).gif?alt=media&#x26;token=b0e7d644-5b50-4044-b4ee-d307cb9fb982" alt=""><figcaption></figcaption></figure>

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

## Syntax

```python
def keyReleased():
    # execute this code when any key is released
    ...
```

<figure><img src="https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2FnqxBXDX1eRuVbBqBlxnn%2Fkeyreleased%202.gif?alt=media&#x26;token=85fb9ae7-c381-4135-8df0-45d9e9c1d0e5" alt=""><figcaption></figcaption></figure>

<details>

<summary>Full Code Example</summary>

```python
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
```

</details>

## Description

Like [draw()](https://learnpython.strivemath.com/p5-python-web/reference/controlling-the-environment/draw) and [setup()](https://learnpython.strivemath.com/p5-python-web/reference/controlling-the-environment/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`](https://learnpython.strivemath.com/p5-python-web/built-in-variables/keyboard#keycode) and [`key`](https://learnpython.strivemath.com/p5-python-web/built-in-variables/keyboard#key) can be used to know which key was released.

{% hint style="info" %}
Find these documents helpful? Let the people who made them help your child learn to code at [**Strivemath**](https://www.strivemath.com/)<mark style="color:blue;">**!**</mark>

We'd love to hear your Feedback/Comments [here](https://docs.google.com/forms/d/e/1FAIpQLSeqorBAGTya-YBRI-VFjJxtgQtCz3ucGDI96K96sNyuaGuvdw/viewform?usp=sf_link).
{% endhint %}
