Keypad Numeric Mode (DECKPNM)

Restore the numeric keypad to its default mode, where keys send their literal digits and operators.

  1. 0x1B
    ESC
  2. 0x3E
    >

Restores the numeric keypad to numeric mode. While this mode is set, the keypad keys transmit their literal characters: digits 0-9, the operators + - * / ., and a carriage return (\r) for Numpad Enter.

This is the inverse of Keypad Application Mode (DECKPAM) and is also the default state at terminal startup and after a hard reset (RIS).

When to send it

Programs that enabled application keypad mode (typically full-screen TUIs such as editors and pagers) must restore numeric mode before exiting, otherwise the user's shell will see escape sequences instead of digits when they press the keypad. Well-behaved curses applications send the matching rmkx/smkx terminfo entries automatically.

Note

DECKPNM and the DEC private mode ?66 (CSI ? 66 l) are equivalent. Resetting either one returns the keypad to numeric mode; setting either one switches to application mode.

Interaction with NumLock and DEC mode 1035

DEC private mode 1035 (default on) makes Wintty ignore the application keypad request outright, so with the default settings the keypad is encoded numerically even while a stale DECKPAM flag is set. Do not rely on that: a program that turned mode 1035 off in order to use the DEC encoding leaves the keypad in application mode until DECKPNM arrives. Always restore numeric mode explicitly when your program no longer needs the DEC private encoding.

Tip

If you observe a shell prompt where pressing keypad digits emits sequences like Op, Oq, Or..., a previous program turned mode 1035 off and then exited without sending DECKPNM. Sending printf "\033>" interactively restores normal behavior.

Validation

DECKPNM V-1: Restores numeric keypad mode

printf "\033[?1035l" # let the keypad request take effect
printf "\033="  # enable application keypad mode first
printf "\033>"  # restore numeric keypad mode

After the last sequence, pressing Numpad 5 should transmit the literal byte 5 again rather than \033Ou. The internal keypad_keys mode flag is now cleared. With mode 1035 left at its default the middle sequence would have had no observable effect in the first place.

DECKPNM V-2: Default state at reset

printf "\033="  # enable application keypad mode
printf "\033c"  # RIS - hard reset

After RIS, the keypad is back in numeric mode without any explicit DECKPNM, because numeric mode is the documented power-on default.