Core Library0.xAPI reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

MoreLess about this notice

method libtmux-dotnet

Pane.SendKeysAsync

Sends keys to the pane.

Source and package
Qualified name
LibTmux.Pane.SendKeysAsync
Namespace
LibTmux
Declared in
Pane
Package
LibTmux
Source
src/LibTmux/Pane.Input.cs
Parameters
Errors
  • ArgumentException – The request sends nothing or its text contains NUL.

  • LibTmuxException – Text was sent, but a requested Enter failed. Its dispatch state is unknown, so the whole request must not be retried.

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 of LibTmux on NuGet: View source

Example.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 using disposes 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 source

Program.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.dll

Expected program output from each framework:

api capture ready

Recorded calls

source calls
No call edges in the C# model.

The 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 material

The tmux commands behind SendKeysAsync.

tmux C API

task material

The C declarations in tmux that implement these commands.

Guides

task material

Pages that discuss SendKeysAsync.

In other ports

task equivalence 16 other ports mapped

Source-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.

Send keystrokes to a pane in each port
PortAPIDiffers from C#
C# LibTmux.Pane.SendKeysAsync
Sends keys to the pane.
This page
Python libtmux.Pane.send_keys
$ tmux send-keys to the pane.
None recorded in the model
Ruby LibTmux::Pane#send_keys
Behavior: Pane input and capture.
None recorded in the model
Lua libtmux.Pane:send_keys None recorded in the model
Erlang tmux_pane:send_keys/2
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-keys
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.Pane.sendKeys
Send keys to this pane, following them with Enter unless told not to.
None recorded in the model
Rust pane.Pane.send_keys
Send keys to the pane as if typed.
None recorded in the model
Go tmux.Pane.SendKeys
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.core/send-keys!
Sends an explicit vector of tmux key names.
free function
Kotlin io.github.libtmux.kotlin.Pane.sendKeys
Sends an ordered group of key names to this pane, as tmux resolves them.
2 overloads
Scala io.github.libtmux.scaladsl.Pane.sendKeys
Sends an ordered group of key names to this pane, as tmux resolves them.
2 overloads
C++ libtmux::Pane::send_text
Literal text, never interpreted as key names or formats, and never followed by a newline the caller did not ask for.
readonly
Swift Server.sendKeys(_:to:literally:)
Sends keys to a pane.
on Server
OCaml Libtmux_unix.Client.send_keys
Send named tmux keys in order, without an implicit Enter. Use send_text for literal bytes rather than key interpretation.
free function
Perl LibTmux::Server::send_keys
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 LibTmux::Model::PaneRef.send-keys
Send native key names, repeating them the requested number of times.
on PaneRef
No Haskell equivalent.

No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.

No Java equivalent.

no direct equivalent; Pane.paste writes a buffer instead

No equivalent is recorded in PowerShell, Julia, Elixir or F#.

Esc
Search in

Type to search.

Reference previewOpen reference