Pane.SendKeysAsync
Sends keys to the pane.
Source and package
- Qualified name
-
LibTmux .Pane. Send Keys Async - Namespace
- LibTmux
- Declared in
Pane- Package
- LibTmux
- Source
- src/LibTmux/Pane.Input.cs
- async Task SendKeysAsync( Send
Keys request, CancellationRequest Token cancellationToken = default ) -
- Parameters
-
-
request(SendKeys ) – What to send.Request -
cancellationToken(CancellationToken ) – Cancels the tmux commands.Default
default
-
- Errors
-
-
Argument
Exception – The request sends nothing or its text contains NUL. -
Lib
Tmux – Text was sent, but a requested Enter failed. Its dispatch state is unknown, so the whole request must not be retried.Exception
-
Examples
Send literal text and a named Enter key, wait for the line the command prints, then require it in the captured pane. All scopes are disposed after errors or cancellation. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as
Example.csproj. It references the 0.1.1 release ofLibTmuxon NuGet: View sourceExample.csproj <Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFrameworks>net8.0;net10.0</TargetFrameworks><LangVersion>12.0</LangVersion><Nullable>enable</Nullable><ImplicitUsings>disable</ImplicitUsings><EnableDefaultCompileItems>false</EnableDefaultCompileItems><TreatWarningsAsErrors>true</TreatWarningsAsErrors><AnalysisLevel>10-recommended</AnalysisLevel></PropertyGroup><ItemGroup><Compile Include="Program.cs" /><PackageReference Include="LibTmux" Version="[0.1.1]" /></ItemGroup></Project>Save this complete program as
Program.cs. It creates a private server;await usingdisposes its owned scopes after success, cancellation or failure. The complete file contains explicit imports, a top-level async entry point and a cancellation deadline. View sourceProgram.csComplete program using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text.RegularExpressions;using System.Threading;using LibTmux;if (OperatingSystem.IsWindows()){throw new PlatformNotSupportedException("This example requires tmux on Linux or macOS.");}using CancellationTokenSource deadline = new(TimeSpan.FromSeconds(10));CancellationToken token = deadline.Token;string? testTmux = Environment.GetEnvironmentVariable("LIBTMUX_TEST_TMUX");string? configured = !string.IsNullOrWhiteSpace(testTmux)? testTmux: Environment.GetEnvironmentVariable("LIBTMUX_TMUX");string binary = string.IsNullOrWhiteSpace(configured) ? "tmux" : configured;using TemporaryDirectory socketRoot = new();ServerConnectionOptions options = new(){SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null",TmuxBinaryPath = binary,};await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);await using OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(new NewSessionRequest{Name = "demo",Command = "env PS1='ready> ' /bin/sh",},token);Server server = await Server.ConnectAsync(options, token);Pane pane = (await server.GetPanesAsync(token)).Single();// The shell has to be reading before anything is typed, or its prompt lands in front of the output.// PS1 rides on the command because a non-interactive bash default-shell drops it from the environment.PaneWaitResult prompt = await pane.WaitForTextAsync(PaneWaitRequest.FromTextPatterns(["ready>"], simpleMatch: true)with{ Timeout = TimeSpan.FromSeconds(5) },token);if (prompt.Outcome is not (PaneWaitOutcome.Matched or PaneWaitOutcome.PresentAtEntry)){throw new InvalidOperationException($"The shell never showed its prompt: {prompt.Outcome}.");}const string marker = "api capture ready";await pane.SendKeysAsync(new SendKeysRequest { Text = $"printf '%s\\n' '{marker}'", Literal = true, Enter = false }, token);await pane.SendKeysAsync(new SendKeysRequest { Text = "Enter", Enter = false }, token);// The echoed command contains the marker, so only a whole line counts as the output.PaneWaitResult printed = await pane.WaitForTextAsync(new PaneWaitRequest{Patterns = [new Regex($"^{Regex.Escape(marker)}$", RegexOptions.CultureInvariant)],Timeout = TimeSpan.FromSeconds(5),},token);if (printed.Outcome is not (PaneWaitOutcome.Matched or PaneWaitOutcome.PresentAtEntry)){throw new InvalidOperationException($"The pane never printed the marker: {printed.Outcome}.");}IReadOnlyList<string> lines = await pane.CaptureAsync(new CapturePaneRequest { JoinWrappedLines = true }, token);// Joining wrapped lines preserves terminal padding after the output.if (!lines.Any(line => string.Equals(line.TrimEnd(), marker, StringComparison.Ordinal))){throw new InvalidOperationException("Capture did not contain the complete output line.");}Console.WriteLine(marker);internal sealed class TemporaryDirectory : IDisposable{private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("libtmux-example-");public string FullName => _directory.FullName;public void Dispose() => _directory.Delete(recursive: true);}Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:
Terminal window $ dotnet build Example.csproj --configuration Release && \dotnet bin/Release/net8.0/Example.dll && \dotnet bin/Release/net10.0/Example.dllExpected program output from each framework:
api capture ready
Recorded calls
source callsThe C# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.Pane.SendKeysAsync.
tmux command
task materialThe tmux commands behind SendKeysAsync.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Guides
task materialPages that discuss SendKeysAsync.
In other ports
task equivalence 16 other ports mappedSource-verified mappings for Send keystrokes to a pane. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.
| Port | API | Differs from C# |
|---|---|---|
| C# | Lib Sends keys to the pane. | This page |
| Python | libtmux $ tmux send-keys to the pane. | None recorded in the model |
| Ruby | Lib Behavior: Pane input and capture. | None recorded in the model |
| Lua | libtmux | None recorded in the model |
| Erlang | tmux Send at most 256 validated key tokens. Named keys, single UTF-8 characters, function keys and control-letter tuples are supported. Performs I/O; terminal modes determine the resulting input bytes. Use send_text/2 for arbitrary bytes. | free function |
| Common Lisp | libtmux: Send a finite nonempty list/vector of tmux key strings to PANE.
Return a COMMAND-OUTCOME. REPEAT is a positive count. Tmux interprets key names
such as C-c and Enter; its unrecognized strings fall back to literal input.
Use SEND-TEXT when key-name interpretation must be disabled. Acknowledgment
does not prove application readiness or consumption. | on client |
| TypeScript | pane Send keys to this pane, following them with Enter unless told not to. | None recorded in the model |
| Rust | pane Send keys to the pane as if typed. | None recorded in the model |
| Go | tmux SendKeys invokes tmux send-keys with the receiver's exact linked session-window-pane target. This is tmux key input, not shell execution: Literal only changes tmux key parsing, and any delivered text may still be interpreted by the pane's application. KeyName routes through a client's key table instead of delivering to the pane. | None recorded in the model |
| Clojure | libtmux Sends an explicit vector of tmux key names. | free function |
| Kotlin | io Sends an ordered group of key names to this pane, as tmux resolves them. | 2 overloads |
| Scala | io Sends an ordered group of key names to this pane, as tmux resolves them. | 2 overloads |
| C++ | libtmux:: Literal text, never interpreted as key names or formats, and never followed by a newline the caller did not ask for. | readonly |
| Swift | Server Sends keys to a pane. | on Server |
| OCaml | Libtmux Send named tmux keys in order, without an implicit Enter. Use send_text for literal bytes rather than key interpretation. | free function |
| Perl | Lib send_keys(pane => Pane|pane_id, keys => arrayref). | on Server Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes. |
| Raku | Lib Send native key names, repeating them the requested number of times. | on PaneRef |
No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
no direct equivalent; Pane.paste writes a buffer instead
No equivalent is recorded in PowerShell, Julia, Elixir or F#.