# keyReleased()

## Example

<figure><img src="/files/UVh3eQyRPeWb54r0TzLk" 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="/files/QA5TyMvp4fgOJn1uXtR8" 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()](/p5-python-web/reference/controlling-the-environment/draw.md) and [setup()](/p5-python-web/reference/controlling-the-environment/setup.md) 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`](/p5-python-web/reference/built-in-variables/keyboard.md#keycode) and [`key`](/p5-python-web/reference/built-in-variables/keyboard.md#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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnpython.strivemath.com/p5-python-web/reference/events/keyboard/keyboard-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
