injectText method

void injectText(
  1. String text
)

Implementation

void injectText(String text) {
  final hadLatch = latch.ctrl || latch.alt || latch.shift;
  if (hadLatch && text.length == 1) {
    final unit = text.codeUnitAt(0);
    if (unit >= 0x20 && unit <= 0x7e) {
      final bytes = encodeKey(
        LogicalKeyboardKey(unit),
        text,
        ctrl: latch.ctrl,
        alt: latch.alt,
        shift: latch.shift,
        modeFlags: modeFlags(),
      );
      if (bytes != null) {
        write(bytes);
        latch.consumeAfterSend();
        return;
      }
    }
  }
  write(Uint8List.fromList(utf8.encode(text)));
  if (hadLatch) latch.consumeAfterSend();
}