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.

method libtmux latest

Pane.send_keys

$ tmux send-keys to the pane.

Source and package
Qualified name
libtmux.Pane.send_keys
Module
libtmux
Declared in
Pane
Package
libtmux
Source
src/libtmux/pane.py
Other languages
Perlmethod Erlang PowerShell Julia Elixir Haskell Common LispRubyLuaTypeScriptRustGo Java C#C++SwiftKotlinScalaOCaml F# Clojure
send_keys
( 12 parameters ) ( self, cmd: str | None = None, enter: bool | None = True, suppress_history: bool | None = False, literal: bool | None = False, reset: bool | None = None, copy_mode_cmd: str | None = None, repeat: int | None = None, expand_formats: bool | None = None, hex_keys: bool | None = None, target_client: str | None = None, key_name: bool | None = None, )
→ None

Description#

A leading space character is added to cmd to avoid polluting the user's history.

When cmd is omitted (None), the wrapper emits a flag-only invocation — useful with reset=True or repeat=N to invoke tmux's deliberate count == 0 branch in cmd-send-keys.c that runs the flag effect without sending any keys. In flag-only mode, enter is forced False (no keys → no Enter).

Examples#

>>> pane = window.split(shell='sh')
>>> pane.capture_pane()
['$']
>>> pane.send_keys('echo "Hello world"', enter=True)
>>> pane.capture_pane()
['$ echo "Hello world"', 'Hello world', '$']
>>> print('\n'.join(pane.capture_pane())) # doctest: +NORMALIZE_WHITESPACE
$ echo "Hello world"
Hello world
$

Flag-only invocation — reset terminal state without sending any keys:

>>> pane.send_keys(reset=True)
Parameters
  • cmd (str | None) # – Text or input into pane. None for flag-only invocation (requires reset, repeat, or copy_mode_cmd to be set). Now optional. None triggers tmux's flag-only path. Versionchanged: 0.57

  • enter (bool | None) # – Send enter after sending the input, default True.

  • suppress_history (bool | None) # – Prepend a space to command to suppress shell history, default False. Default changed from True to False. Versionchanged: 0.14

  • literal (bool | None) # – Send keys literally, default False.

  • reset (bool | None) # – Reset terminal state before sending keys (-R flag). added 0.56

  • copy_mode_cmd (str | None) # – Send a command to copy mode instead of keys (-X flag). When set, cmd is ignored. added 0.56

  • repeat (int | None) # – Repeat count for the key (-N flag). added 0.56

  • expand_formats (bool | None) # – Expand tmux format strings in keys (-F flag). added 0.56

  • hex_keys (bool | None) # – Send keys as hex values (-H flag). added 0.56

  • target_client (str | None) # – Specify a target client (-c flag). Requires tmux 3.4+. added 0.56

  • key_name (bool | None) # – Handle keys as key names (-K flag). Requires tmux 3.4+. added 0.56

Raises
  • ValueError – If cmd is None and no flag-only path is selected (reset, repeat, or copy_mode_cmd).

tmux command#

The tmux commands behind send_keys.

tmux C API#

The C declarations in tmux that implement these commands.

Guides#

Pages that discuss send_keys.

Guides

In other ports#

Send keystrokes to a pane

Equivalents of Send keystrokes to a pane in other languages
Language Equivalent
Ruby LibTmux::Pane#send_keys
Lua libtmux.Pane:send_keys
Erlang tmux_pane:send_keys/2
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
Common Lisp libtmux:send-keys
TypeScript pane.Pane.sendKeys
Rust pane.Pane.send_keys
Go tmux.Pane.SendKeys
Java no direct equivalent; Pane.paste writes a buffer instead
Clojure libtmux.core/send-keys!
Kotlin io.github.libtmux.kotlin.Pane.sendKeys
Scala io.github.libtmux.scaladsl.Pane.sendKeys
C# LibTmux.Pane.SendKeysAsync
C++ libtmux::Pane::send_text
Swift Server.sendKeys(_:to:literally:)
OCaml Libtmux_unix.Client.send_keys
Perl LibTmux::Server::send_keys Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes.

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

Esc

Type to search.

Reference previewOpen reference