On this page
libtmux.Pane.send_keys
- Module
- libtmux
- Declared in
- Pane
- Package
- libtmux
- Source
- src/libtmux/pane.py
- Other languages
- TypeScriptRustGo Java .NETC++Swift
-
$ tmux send-keysto the pane.A leading space character is added to cmd to avoid polluting the user's history.
When
cmdis omitted (None), the wrapper emits a flag-only invocation — useful withreset=Trueorrepeat=Nto invoke tmux's deliberatecount == 0branch incmd-send-keys.cthat runs the flag effect without sending any keys. In flag-only mode,enteris forcedFalse(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.
Nonefor flag-only invocation (requiresreset,repeat, orcopy_mode_cmdto be set). Now optional.Nonetriggers 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 (
-Rflag). added 0.56 -
copy_mode_cmd ( str | None ) – Send a command to copy mode instead of keys (
-Xflag). When set, *cmd* is ignored. added 0.56 -
repeat ( int | None ) – Repeat count for the key (
-Nflag). added 0.56 -
expand_formats ( bool | None ) – Expand tmux format strings in keys (
-Fflag). added 0.56 -
hex_keys ( bool | None ) – Send keys as hex values (
-Hflag). added 0.56 -
target_client ( str | None ) – Specify a target client (
-cflag). Requires tmux 3.4+. added 0.56 -
key_name ( bool | None ) – Handle keys as key names (
-Kflag). Requires tmux 3.4+. added 0.56
-
- Raises
-
-
ValueError – If
cmdisNoneand no flag-only path is selected (reset,repeat, orcopy_mode_cmd).
-
Discussed in Pane interaction
In other languages Send keystrokes to a pane
- TypeScript
pane.Pane.sendKeys - Rust
pane.Pane.send_keys - Go
tmux.Pane.SendKeys - Java no direct equivalent; `Pane.paste` writes a buffer instead
- .NET
LibTmux.Pane.SendKeysAsync - C++
libtmux::Pane::send_text - Swift
Server.sendKeys(_:to:literally:)
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