> For the complete documentation index, see [llms.txt](https://docs.anvil.team/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anvil.team/namespaces/key.md).

# key

Let's you check if keys are pressed etc.

{% hint style="info" %}
Key codes can be found here

<https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes>
{% endhint %}

### Methods

* [isPressed](#key.ispressed-keycode)
* [isDown](#key.isdown-keycode)

### <mark style="color:green;">`key.isPressed(keyCode)`</mark>

* <mark style="color:purple;">`keyCode`</mark> - The code of the key

Returns true if given key is pressed.

**Example:**

```lua
-- Turns around 180 degree if pressing A key
if (key.isPressed(0x41)) then
    local view = player.getView()
    view.y = view.y + 180
    player.setView(view)
end
```

### <mark style="color:green;">`key.isDown(keyCode)`</mark>

* <mark style="color:purple;">`keyCode`</mark> - The code of the key

Returns true if given key is down right now.

**Example:**

```lua
-- Prints while you hold down D key
while (key.isDown(0x44)) do
    print("D key is being held")
end
```
