Back to Projects
TUIX v0.6Beta

Last Updated: 2026-08-14

Input API

The tuix.core.input module controls the native listener and exposes consuming, non-consuming snapshots, and synthetic key injection. Built-in widgets receive input automatically through core.main_loop().

MethodHow to use itWhy it exists
input.tuix_input_start() -> NoneStarts background native listener thread.Captures raw terminal keyboard and mouse events into thread-safe ring buffer.
input.tuix_input_stop() -> NoneStops background native listener thread.Terminates input listener during application teardown.
input.tuix_input_get_snapshot() -> InputSnapshotConsumes and returns next input snapshot from the queue.Advances input queue during frame loop.
input.tuix_input_peek_snapshot() -> InputSnapshotInspects latest input snapshot without consuming queued events.Diagnostic and predictive input checking.
input.tuix_input_inject_key(key: int, ctrl: int = 0, alt: int = 0, shift: int = 0, event_type: int = 1, payload_utf8: bytes = b'') -> NoneInjects synthetic keyboard event into native input queue.Programmatic automation, keybinding dispatch, and unit testing.

Snapshot Shape

  • InputSnapshot: term_x, term_y, keyboard, mouse, consumed_keyboard, consumed_mouse.
  • KeyboardKey: btn, code, scancode, modifiers, pressed, repeat, has_event, payload_utf8 (128-byte UTF-8 payload for grapheme clusters and text input).
  • MouseKey: event, btn, buttons_held, col, row, has_event.

Usage Pattern

input.listen()
try:
    while running:
        core.main_loop()
        latest = input.peek_snapshot()  # optional diagnostics
finally:
    input.stop()