class RatatuiRuby::Event::Key

Captures a keyboard interaction.

The keyboard is the primary interface for your terminal application. Raw key codes are often cryptic, and handling modifiers manually is error-prone.

This event creates clarity. It encapsulates the interaction, providing a normalized code and a list of active modifiers.

Compare it directly to strings or symbols for rapid development, or use pattern matching for complex control schemes.

Examples

Using predicates:

if event.key? && event.ctrl? && event.code == "c"
  exit
end

Using symbol comparison:

if event == :ctrl_c
  exit
end

Using pattern matching:

case event
in type: :key, code: "c", modifiers: ["ctrl"]
  exit
end

Terminal Compatibility

Some key combinations never reach your application. Terminal emulators intercept them for built-in features like tab switching. Common culprits:

If modifiers appear missing, test with a different terminal. Kitty, WezTerm, and Alacritty pass more keys through. See doc/terminal_limitations.md for details.

Enhanced Keys (Kitty Protocol)

Terminals supporting the Kitty keyboard protocol report additional keys:

These keys will not work in Terminal.app, iTerm2, or GNOME Terminal.