etui/keys

Types

pub type Key {
  Char(String)
  Up
  Down
  Left
  Right
  Enter
  Backspace
  Delete
  Tab
  BackTab
  Home
  End
  PageUp
  PageDown
  Escape
  Insert
  F(Int)
  Ctrl(String)
  Alt(String)
  Unknown(String)
}

Constructors

  • Char(String)

    Plain printable character (single grapheme, not a control key).

  • Up
  • Down
  • Left
  • Right
  • Enter
  • Backspace
  • Delete
  • Tab
  • BackTab
  • Home
  • End
  • PageUp
  • PageDown
  • Escape
  • Insert
  • F(Int)

    F1–F12

  • Ctrl(String)

    Ctrl+, e.g. Ctrl(“c”), Ctrl(“d”)

  • Alt(String)

    Alt+, e.g. Alt(“f”)

  • Unknown(String)

    Unknown / unrecognised key string.

Values

pub fn char_value(k: Key) -> String

Extract the character string from a Char key. Returns "" for others.

pub fn is_char(k: Key) -> Bool

True if key is a printable character (not a control/special key).

pub fn is_modifier(k: Key) -> Bool

True if the key is a modifier combo (Ctrl or Alt).

pub fn is_navigation(k: Key) -> Bool

True if the key is a navigation key (arrows, home, end, page up/down).

pub fn match(raw: String) -> Key

Parse a raw key string (from backend.KeyPress) into a Key.

Raw strings from the Erlang backend follow these conventions:

  • Printable ASCII/Unicode: the character itself (e.g. "a", "A", "€")
  • Arrow keys: "up", "down", "left", "right"
  • Control keys: "enter", "backspace", "delete", "tab", "backtab", "home", "end", "pageup", "pagedown", "esc", "insert"
  • Function keys: "f1""f12"
  • Ctrl combos: "ctrl+a""ctrl+z", "ctrl+[", etc.
  • Alt combos: "alt+a""alt+z", etc.
Search Document