sendKey method

bool sendKey({
  1. required GhosttyKey key,
  2. GhosttyKeyAction action = GhosttyKeyAction.GHOSTTY_KEY_ACTION_PRESS,
  3. int mods = 0,
  4. int consumedMods = 0,
  5. bool composing = false,
  6. String utf8Text = '',
  7. int unshiftedCodepoint = 0,
})

Encodes and sends a key event using Ghostty's keyboard protocol rules.

Implementation

bool sendKey({
  required GhosttyKey key,
  GhosttyKeyAction action = GhosttyKeyAction.GHOSTTY_KEY_ACTION_PRESS,
  int mods = 0,
  int consumedMods = 0,
  bool composing = false,
  String utf8Text = '',
  int unshiftedCodepoint = 0,
}) {
  if (_process == null && _ptySession == null) {
    return false;
  }

  _encoder ??= VtKeyEncoder();
  final terminal = _terminal;
  if (terminal != null) {
    _encoder!.setOptionsFromTerminal(terminal);
  }

  final event = VtKeyEvent();
  try {
    event
      ..action = action
      ..key = key
      ..mods = mods
      ..consumedMods = consumedMods
      ..composing = composing
      ..utf8Text = utf8Text
      ..unshiftedCodepoint = unshiftedCodepoint;
    final encoded = _encoder!.encode(event);
    return writeBytes(encoded);
  } finally {
    event.close();
  }
}