> ## Documentation Index
> Fetch the complete documentation index at: https://luau.limerence.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Key

> A keybind picker.

Also has everything from [ElementHandle](/ui/classes/element-handle).

A keybind picker. Value is the chosen key (`Enum.KeyCode`, `Enum.UserInputType`, or `nil`).

|                  |                                              |
| ---------------- | -------------------------------------------- |
| **Value type**   | `Enum.KeyCode \| Enum.UserInputType \| nil`  |
| **Default mode** | `"onPress"`                                  |
| **Created by**   | [Section:AddKey](/ui/classes/section#addkey) |

## Creation

```luau theme={null}
section:AddKey(key, label, default?, mode?)
```

<ParamField path="mode" type="KeyMode">
  See [KeyMode](/reference/types#keymode). Controls when `OnCallback` reports active.
</ParamField>

***

## SetKey

```luau theme={null}
keyHandle:SetKey(key: Enum.KeyCode | Enum.UserInputType | nil): ()
```

Set the keybind. Pass `nil` to clear it.

***

## SetMode

```luau theme={null}
keyHandle:SetMode(mode: KeyMode): ()
```

| Mode          | What `active` means           |
| ------------- | ----------------------------- |
| `"onPress"`   | `true` while held after press |
| `"onRelease"` | Fires on release              |
| `"onHold"`    | `true` while held             |
| `"toggle"`    | Toggles on each press         |

***

## OnCallback

```luau theme={null}
keyHandle:OnCallback(callback: (active: boolean) -> ()): () -> ()
```

Runs `cb(active)`. What `active` means depends on the mode (e.g. `true` while held in `"onHold"`).

***

## SetListening

```luau theme={null}
keyHandle:SetListening(listening: boolean): ()
```

Manually put the picker into "waiting for input" mode. `GetValue` / `SetValue` are the bound key.
