Skip to main content
ansicode

XTMODKEYS — Modify keyboard reporting (CSI > Pp ; Pv m)

Switch xterm's modifyKeyboard / modifyCursorKeys / modifyFunctionKeys / modifyOtherKeys resources at runtime — the foundation for Ctrl+letter, Alt+letter disambiguation.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[><Pp>;<Pv>m
\\033[\033[>4;2m
\\e[\e[>4;2m
ESC [ESC [ > Pp ; Pv m
hex1b 5b 3e ... 6d

Description

The `>` prefix flips the `m` final byte from SGR (set-graphic-rendition) to XTMODKEYS — a runtime-mutable view of four xterm resources that control how modifier-laden keys are reported. The first parameter `Pp` selects the resource (`0` = modifyKeyboard, `1` = modifyCursorKeys, `2` = modifyFunctionKeys, `3` = modifyKeypadKeys is reserved, `4` = modifyOtherKeys), and `Pv` sets its value. The killer feature is **modifyOtherKeys** (`Pp=4`): with `Pv=0` xterm only reports Ctrl+letter as the corresponding C0 byte (Ctrl+I === Tab, Ctrl+M === Enter), with `Pv=1` it reports modified versions of unambiguous keys via CSI 27 ~, and with `Pv=2` it reports **every** modified printable key — letting editors like vim/emacs/kakoune distinguish Ctrl+I from Tab, Ctrl+H from Backspace, and bind Alt+letter without the legacy ESC-prefix hack. Reset by emitting `\x1b[>Pp m` with no `Pv` (restores xterm default) or `\x1b[>4;0m` to leave modifyOtherKeys mode. Kitty's CSI u keyboard protocol (separate sequence) offers a strictly richer alternative and is preferred for greenfield code; XTMODKEYS remains the de-facto compatibility path for the millions of TUIs already targeting xterm.

Spec citation: xterm-ctlseqs (XTMODKEYS)

Parameters

PpResource selector: `0` modifyKeyboard, `1` modifyCursorKeys, `2` modifyFunctionKeys, `4` modifyOtherKeys.
PvNew value for the resource. For modifyOtherKeys: `0` off, `1` modified-only-when-unambiguous, `2` always modified.

Examples

bash
# Enable full modifyOtherKeys — every Ctrl+letter reports distinctly:\nprintf '\033[>4;2m'\n# (run from inside a TUI that handles CSI 27 ~ replies; raw shells will show garbage)
python
import sys\nsys.stdout.write('\x1b[>4;2m')   # enable modifyOtherKeys 2\n# remember to send '\x1b[>4;0m' on exit to restore default
go
fmt.Print("\x1b[>4;1m")   // modifyOtherKeys mode 1
javascript
process.stdout.write('\x1b[>4;2m')   // enable full modify-other-keys
c
printf("\x1b[>4;2m");   /* opt in to fully-modified key reports */\natexit_send("\x1b[>4;0m");  /* opt out at exit */

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
no
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
no
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
partial
Konsole
yes
tmux
no
GNU screen
no

Related sequences