# Keyboard Action Mode (KAM)

> Lock and unlock the keyboard.

- **Sequence:** `CSI 2 h`
- **ECMA-48:** [§7.2.11 KAM – Keyboard Action Mode, p. 24](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n37/mode/1up)
- **DEC STD 070:** [§5.10.1.1 ANSI Specified Modes, p. 5-133](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n387/mode/1up)
- **VT220:** [§4.6.3 Keyboard Action Mode (KAM)](https://vt100.net/docs/vt220-rm/chapter4.html#S4.6.3)
- **VT510:** [KAM—Keyboard Action Mode](https://vt100.net/docs/vt510-rm/KAM.html)
- **xterm:** [Functions using CSI](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

Mode 2 locks the keyboard. Set (`CSI 2 h`), the keyboard sends nothing to
the host; reset (`CSI 2 l`), which is the default, it works as usual.

| State | ECMA-48 calls it | Meaning |
| --- | --- | --- |
| Reset, `CSI 2 l` | ENABLED | the keyboard can be used |
| Set, `CSI 2 h` | DISABLED | all or part of the keyboard cannot be used |

DEC STD 070 lists it among the ANSI modes a DEC terminal accepts, and its
keyboard chapter
([p. 6-37](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n523/mode/1up)) says that when it is locked all but the
local function keys F1 to F5 are disabled. The VT510 manual adds that the
terminal shows its Wait indicator, and that Set-Up and the session key still
work.

xterm keeps the mode, and while it is set it ignores what is typed
([`input.c`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/input.c#L1014-L1016)). It changes only what the keyboard
sends, which this site cannot press, so nothing on the screen changes.
libghostty-vt keeps the mode too, and both answer [DECRQM](https://control-codes.page/csi/decrqm/index.html.md)
with its state.

## Validation

### KAM-1: Reset by default

Input, one step per line:

```text
\e[2$p
```

Expected screen:

```text
|_____|
reply \e[2;2$y
```

### KAM-2: Set

Input, one step per line:

```text
\e[2h
\e[2$p
```

Expected screen:

```text
|_____|
reply \e[2;1$y
```

### KAM-3: And reset again

Input, one step per line:

```text
\e[2h
\e[2l
\e[2$p
```

Expected screen:

```text
|_____|
reply \e[2;2$y
```

### KAM-4: Nothing on the screen changes

Input, one step per line:

```text
A
\e[2h    # lock the keyboard
B
\e[2l
C
```

Expected screen:

```text
|ABC__|
cursor 1,4
```

---

This is the Markdown version of <https://control-codes.page/ansi/kam/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
