> For the complete documentation index, see [llms.txt](https://learnpython.strivemath.com/p5-python-web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnpython.strivemath.com/p5-python-web/reference/built-in-functions/keyisdown.md).

# keyIsDown()

### Example

<figure><img src="/files/9d0VVC47OQ75cqKH29Uh" alt=""><figcaption></figcaption></figure>

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

<details>

<summary>Example Full Code</summary>

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

</details>

### Default inputs

```python
keyIsDown(VALUE)
```

| Input | Description                       |
| ----- | --------------------------------- |
| VALUE | key code of the key being checked |

### Description

The **keyIsDown()** function checks if a certain key is currently **down (Pressed)**. It returns `True` if that key is down, and `False` if it does not.  (Boolean datatype)

For example, `keyIsDown(`**`38`**`)`checks whether the **up arrow** is being pushed, since **38** is its keycode.

Similarly, `keyIsDown(`**`UP_ARROW`**`)`checks for the same thing, because **UP\_ARROW** is a constant that stores the key code of the up arrow, other such constants include **DOWN\_ARROW**, **ENTER** and **SHIFT**.

In general, you can search the web for: `key code of ###` or look at [this website](https://www.toptal.com/developers/keycode).

{% 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://learnpython.strivemath.com/p5-python-web/reference/built-in-functions/keyisdown.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
