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