ui/keyboard

Keyboard event decoding and view helpers for Glizzy components.

Provides a shared KeyEvent type with modifier keys and a helper that decodes full DOM keyboard events for component keymaps.

Types

A normalized key type for easier pattern matching in keymaps.

pub type Key {
  Space
  Enter
  Escape
  Tab
  Shift
  Control
  Alt
  Meta
  ArrowUp
  ArrowDown
  ArrowLeft
  ArrowRight
  Home
  End
  PageUp
  PageDown
  Delete
  Backspace
  F1
  F2
  F3
  F4
  F5
  F6
  F7
  F8
  F9
  F10
  F11
  F12
  Character(String)
  Unknown
}

Constructors

  • Space
  • Enter
  • Escape
  • Tab
  • Shift
  • Control
  • Alt
  • Meta
  • ArrowUp
  • ArrowDown
  • ArrowLeft
  • ArrowRight
  • Home
  • End
  • PageUp
  • PageDown
  • Delete
  • Backspace
  • F1
  • F2
  • F3
  • F4
  • F5
  • F6
  • F7
  • F8
  • F9
  • F10
  • F11
  • F12
  • Character(String)
  • Unknown

A decoded keyboard event with modifier key state.

pub type KeyEvent {
  KeyEvent(
    key: String,
    shift: Bool,
    ctrl: Bool,
    meta: Bool,
    alt: Bool,
  )
}

Constructors

  • KeyEvent(
      key: String,
      shift: Bool,
      ctrl: Bool,
      meta: Bool,
      alt: Bool,
    )

Values

pub fn decode_key(key_string: String) -> Key

Decode a key string from a KeyEvent into a normalized Key type.

pub const default_typeahead_timeout_ms: Int

Default timeout for type-ahead buffer in milliseconds.

pub fn first_index(item_count: Int) -> Int

Get the first index (always 0).

pub fn is_activation_key(key: Key) -> Bool

Check if a key is an activation key.

pub fn is_character_key(key: Key) -> Bool

Check if a key is a character key.

pub fn is_navigation_key(key: Key) -> Bool

Check if a key is a navigation key.

pub fn last_index(item_count: Int) -> Int

Get the last index.

pub fn next_index(
  current: Int,
  item_count: Int,
  wrap: Bool,
) -> Int

Calculate the next index in a circular list.

pub fn on_keydown(
  handler: fn(KeyEvent) -> msg,
) -> attribute.Attribute(msg)

Attach a keydown handler that decodes the full KeyEvent with modifier keys.

pub fn on_keydown_prevent(
  handler: fn(KeyEvent) -> msg,
) -> attribute.Attribute(msg)

Attach a keydown handler with preventDefault for all dispatched keys.

pub fn prev_index(
  current: Int,
  item_count: Int,
  wrap: Bool,
) -> Int

Calculate the previous index in a circular list.

pub fn type_ahead_match(
  items: List(String),
  current: Int,
  char: String,
) -> Int

Find the next item that starts with the given character.

pub fn typeahead_match(
  items: List(String),
  current: Int,
  buffer: String,
) -> Int

Find the next item that starts with the given buffer string.

pub fn update_typeahead_buffer(
  current_buffer: String,
  last_keypress_time: Int,
  current_time: Int,
  new_char: String,
  timeout_ms: Int,
) -> #(String, Bool)

Update type-ahead buffer with new character.

Search Document