# LibTmux.Pane.SendKeysAndWaitAsync

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** C#
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-dotnet/blob/cf34b255c896d19a97e7d7fabea58609c916012d/src/LibTmux/Pane.Waiting.cs#L151
- **Page:** https://libtmux.org/en/csharp/latest/reference/libtmux-pane-sendkeysandwaitasync/

```
LibTmux.Pane.SendKeysAndWaitAsync(keys: SendKeysRequest, wait: PaneWaitRequest, cancellationToken: CancellationToken) -> Task<PaneWaitResult>
```

Sends keys to the pane and waits for what it prints in response.

The wait reads the screen before the keys go, so output that follows at
once is not missed, and judges only what the pane prints afterwards:
text already on screen never ends it. A shell echoes typed text back, so
literal text (<see cref="SendKeysRequest.Literal" />, as
<see cref="SendTextAsync" /> sends) is removed from what the pane shows
before matching, including the part of a line the shell has echoed so
far. Waiting for <c>done</c> after typing <c>echo done</c> therefore
waits for the command's output, not for the line that was typed.

The removal is by text: output identical to a typed line, as a whole
word, is removed too. Key names, and text sent with
<see cref="SendKeysRequest.ExpandFormats" />,
<see cref="SendKeysRequest.Repeat" /> or a copy-mode command, are not
removed.

A typed line the pane wrapped onto a second row is still recognised.
Like <see cref="WaitForTextAsync(PaneWaitRequest, CancellationToken)" />,
the wait sleeps on the pane's output through a control-mode client.
Typed literal text may be at most 65536 UTF-8 bytes; ordinary
<see cref="SendKeysAsync(SendKeysRequest, CancellationToken)" /> has no
echo-projection limit.

## Parameters

- `keys` (`SendKeysRequest`): What to type.
- `wait` (`PaneWaitRequest`): The patterns that end the wait, and how long to wait.
- `cancellationToken` (`CancellationToken`): Stops the wait; keys already sent stay sent.

## Returns

How the wait ended.

## Raises

- [`ArgumentException`](https://learn.microsoft.com/dotnet/api/system.argumentexception): The request has no patterns or typed literal text exceeds 65536 UTF-8 bytes.
- [`ArgumentOutOfRangeException`](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception): The timeout is negative or longer than 49 days.
- [`IOException`](https://learn.microsoft.com/dotnet/api/system.io.ioexception): Echo projection exceeds its bounded work.
- [`RegexMatchTimeoutException`](https://learn.microsoft.com/dotnet/api/system.text.regularexpressions.regexmatchtimeoutexception): Echo matching exceeds its finite regex time.
- [`TmuxPaneException`](/en/csharp/latest/reference/libtmux-tmuxpaneexception/): The pane's program had already exited, or the pane changed during every read until the timeout, so nothing was sent.
- [`TmuxObjectNotFoundException`](/en/csharp/latest/reference/libtmux-tmuxobjectnotfoundexception/): tmux no longer has the pane.
- [`LibTmuxException`](/en/csharp/latest/reference/libtmux-libtmuxexception/): The text was sent but a requested Enter failed. The pane may already
have acted on the text; do not retry the whole call.
