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

# Keys and binds

Keyboard and mouse state, key codes and ways to bind an action to a key.

`keys()` shows what is actually held down on the keyboard and mouse. It queries the system directly, so it gives the right result even with a screen open and does not depend on Quick's binds.

```java
@Override
public void onTick() {
    if (keys().inputBlocked()) return;
    if (keys().isDown(Keys.LEFT_SHIFT) && keys().mouseDown(Keys.MOUSE_RIGHT)) chat("Shift and right mouse button are held");
}
```

## Keys

| Method                           | Type      | Description                                                  |
| -------------------------------- | --------- | ------------------------------------------------------------ |
| `isDown(key)`                    | `boolean` | whether a key is held, GLFW code                             |
| `mouseDown(button)`              | `boolean` | whether a mouse button is held: 0 left, 1 right, 2 middle    |
| `mouseX()`, `mouseY()`           | `float`   | cursor position in window pixels                             |
| `cursorLocked()`                 | `boolean` | whether the cursor is grabbed by the camera                  |
| `lockCursor()`, `unlockCursor()` | `void`    | grab or release the cursor                                   |
| `inputBlocked()`                 | `boolean` | whether input is taken by chat, Quick's menu or a text field |
| `name(key)`                      | `String`  | key label the way Quick shows it: `"Left Shift"`             |
| `code(name)`                     | `int`     | code for a label, or `Keys.UNKNOWN`                          |

The cursor position is returned in pixels, while `Render2D` draws in GUI units. To convert, divide the coordinates by `control().guiScale()`.

## Codes

Ready-made constants: `Keys.LEFT_SHIFT`, `LEFT_CONTROL`, `LEFT_ALT`, `SPACE`, `ENTER`, `TAB`, `ESCAPE`, `MOUSE_LEFT`, `MOUSE_RIGHT`, `MOUSE_MIDDLE`, `UNKNOWN`. Other keys use regular GLFW codes: letter codes match uppercase ASCII letters (`'F'` = 70), digit codes match ASCII digits.

## Three ways to bind an action to a key

| Way                           | When to use it                                                                          |
| ----------------------------- | --------------------------------------------------------------------------------------- |
| `hotkey("Name", 'F', action)` | the player should be able to rebind the key in the menu; Quick runs the action on press |
| `on(KeyEvent.class, …)`       | you need modifiers, key release or a reaction while a screen is open                    |
| `keys().isDown(…)` in a tick  | what matters is that the key is held, not the moment it was pressed                     |

More about hotkeys in [Kinds of settings](/en/settings/types.md), about events on the [Subscribing to events](/en/events/basics.md) page.


---

# 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://docs.quickclient.cc/en/actions/keys.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.
