Skip to content

Conversation

@justinpopa
Copy link

This implements the solution requested in #860 by adding distinct
KeyCode enum variants for numeric keypad keys, allowing applications
to differentiate between main keyboard numbers and keypad numbers.

New KeyCode variants added:

  • Keypad0-9: Numeric keypad keys
  • KeypadMultiply (*), KeypadPlus (+), KeypadMinus (-), KeypadDivide (/): Operators
  • KeypadPeriod (.), KeypadComma (,), KeypadEqual (=), KeypadEnter: Additional keys

Platform implementations:

  • Unix: Parses DECKPAM (DEC Keypad Application Mode) escape sequences with modifiers (Shift, Alt, Ctrl, and combinations) using the standard xterm modifier encoding (ESC O ). Also extends modifier support to existing ESC O sequences (arrows, Home, End, F1-F4).
  • Windows: Maps VK_NUMPAD virtual key codes to the new KeyCode variants. Usage of modifier + numpad varies on windows. A number of those combinations are already in use by Windows, so they are of limited practicality.

Closes #860

This implements the solution requested in crossterm-rs#860 by adding distinct
KeyCode enum variants for numeric keypad keys, allowing applications
to differentiate between main keyboard numbers and keypad numbers.

New KeyCode variants added:
- Keypad0-9: Numeric keypad keys
- KeypadMultiply (*), KeypadPlus (+), KeypadMinus (-),
  KeypadDivide (/): Operators
- KeypadPeriod (.), KeypadComma (,), KeypadEqual (=),
  KeypadEnter: Additional keys

Platform implementations:
- Unix: Parses DECKPAM (DEC Keypad Application Mode) escape
  sequences with modifiers (Shift, Alt, Ctrl, and combinations)
  using the standard xterm modifier encoding (ESC O <modifier>
  <key>). Also extends modifier support to existing ESC O
  sequences (arrows, Home, End, F1-F4).
- Windows: Maps VK_NUMPAD virtual key codes to the new KeyCode
  variants. Usage of modifier + numpad varies on Windows. A
  number of those combinations are already in use by Windows,
  so they are of limited practicality.

Closes crossterm-rs#860
@justinpopa justinpopa requested a review from TimonPost as a code owner October 2, 2025 21:28
…mmands

Refactors DECKPAM modifier parsing to use the existing parse_modifiers()
function for consistency with CSI sequences, rather than duplicating the
modifier extraction logic with a manual match statement. The ASCII digit
modifier code ('2'-'8') is converted to its numeric value (2-8) before
passing to parse_modifiers().

Adds EnableApplicationKeypad and DisableApplicationKeypad commands to
allow applications to control DECKPAM mode, following the same pattern
as other terminal mode commands (EnableMouseCapture, EnableFocusChange,
etc.). This makes the keypad feature complete and discoverable without
requiring users to know raw escape sequences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Differentiate between keyboard/numpad chars

1 participant