Core LibrarystableAPI Reference

Choose documentation 3

stable

Current version

stable
English

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

Python API

method libtmux stable

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
PowerShell Julia RubyLuaTypeScriptRustGo Java C#C++SwiftKotlinScala F#
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 send-keys

Discussed in Sending keys · Pane interaction

In other ports Send keystrokes to a pane
Esc

Type to search.

Reference preview Open reference