Keypad Application Mode (DECKPAM)

Switch the numeric keypad into application mode so its keys send DEC private escape sequences instead of literal digits.

  1. 0x1B
    ESC
  2. 0x3D
    =

Switches the numeric keypad into application mode. While this mode is set, pressing a keypad key sends a DEC private escape sequence of the form ESC O x (where x identifies the specific key) instead of the literal digit, operator, or Enter byte.

This is the inverse of Keypad Numeric Mode (DECKPNM), which restores the default behavior where the keypad sends literal characters.

Encoded sequences

In application mode, the keypad sends the following sequences:

KeySequence
Numpad 0-9ESC O p through ESC O y
Numpad .ESC O n
Numpad /ESC O o
Numpad *ESC O j
Numpad -ESC O m
Numpad +ESC O k
Numpad EnterESC O M

In numeric mode (the default and the state after a terminal reset), the same keys send their literal characters (e.g. keypad 5 sends 5, keypad Enter sends \r).

Note

DECKPAM and the DEC private mode ?66 (CSI ? 66 h / CSI ? 66 l) are two ways to control the same internal state. Setting either one enables application keypad mode; resetting either one disables it.

Interaction with NumLock and DEC mode 1035

On real PCs, the keypad doubles as a cursor pad when NumLock is off. xterm exposes this through DEC private mode 1035 (default on). While that mode is on Wintty ignores the application keypad request unconditionally, whatever the host reports for NumLock: the keypad is always encoded numerically. With the default settings, ESC = therefore has no observable effect on what the keypad transmits until a program turns mode 1035 off with CSI ? 1035 l.

Tip

Most modern full-keyboards do not surface a NumLock state to the terminal at all, which is why mode 1035 defaults to on. A program that really wants the DEC keypad encoding has to send CSI ? 1035 l before ESC =.

Validation

DECKPAM V-1: Enables application keypad mode

printf "\033[?1035l" # stop ignoring the application keypad request
printf "\033="

After both sequences, pressing Numpad 5 should transmit \033Ou instead of the literal 5. Without the first sequence the keypad mode flag is still set, but mode 1035 keeps the encoding numeric, so nothing about the transmitted bytes changes.

No terminfo capability reports this flag. The related capabilities are smkx/keypad_xmit and rmkx/keypad_local, and Wintty's smkx is \E[?1h\E=, which also sets the cursor key mode, so it is not the same byte sequence a program sends with a bare ESC =.