Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Python API

Python documentation

View as Markdown

Module
libtmux
Declared in
Pane
Package
libtmux
Source
src/libtmux/pane.py
Other languages
RubyLuaTypeScriptRustGo Java .NETC++Swift
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
method [source]
method [source]
send_keys

$ tmux send-keys to the pane.

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

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

Discussed in Pane interaction

In other ports Send keystrokes to a pane

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)
await pane.sendKeys("echo hello");
await pane.sendKeys("C-c", { literal: false });

0 declared, 0 inherited

Esc

Type to search.