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

# input

Teclado e mouse.

| Função                                      | Devolve                                                                                      |
| ------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `input.is_key_down(key)`                    | `true` enquanto a tecla está apertada                                                        |
| `input.is_key_pressed(key, [repeat=false])` | `true` no frame em que foi apertada; com `repeat`, também a cada repetição enquanto segurada |
| `input.is_key_released(key)`                | `true` no frame em que foi solta                                                             |
| `input.is_mouse_down([button=1])`           | Botão do mouse apertado: 1 esquerdo, 2 direito, 3 meio, 4 e 5 laterais                       |
| `input.mouse_pos()`                         | `x, y` do mouse na tela                                                                      |
| `input.mouse_wheel()`                       | Quanto a rodinha girou neste frame (positivo = para cima)                                    |
| `input.typing()`                            | `true` enquanto a pessoa digita num campo do menu (busca, chat, editor)                      |
| `input.key_name(key)`                       | Nome oficial de uma tecla: `input.key_name("mouse4")` devolve `"MouseX1"`                    |

`key` é um [nome de tecla](/referencia/teclas.md), como `"F"`, `"Space"`, `"LeftShift"` ou `"Mouse4"`. Nomes desconhecidos dão erro.

```lua
callbacks.add("draw", function()
    if input.typing() then return end           -- ignore keys while typing
    if input.is_key_pressed("F6") then
        menu.set("world.third_person", not menu.get("world.third_person"))
    end
end)
```

{% hint style="info" %}
Para teclas que a pessoa escolhe, prefira [`ui.keybind`](/documentacao/api/ui.md#ui-keybind) com `:is_down()` e `:is_pressed()`. Assim a tecla aparece no menu e pode ser trocada sem mexer no código.
{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.perfectcs2.com/documentacao/api/input.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
