# libtmux.Pane.send_keys

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/pane.py#L675
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-pane-send_keys/

tmux command: [`send-keys`](/en/tmux/latest/manual/send-keys/)

```
libtmux.Pane.send_keys(
    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
```

[`$ tmux send-keys`](/en/tmux/latest/manual/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).

## Examples

```python
>>> pane = window.split(shell='sh')
>>> pane.capture_pane()
['$']
```

```python
>>> pane.send_keys('echo "Hello world"', enter=True)
```

```python
>>> pane.capture_pane()
['$ echo "Hello world"', 'Hello world', '$']
```

```python
>>> print('\n'.join(pane.capture_pane()))  # doctest: +NORMALIZE_WHITESPACE
$ echo "Hello world"
Hello world
$
```

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

```python
>>> 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`](https://docs.python.org/3/library/exceptions.html#ValueError): If ``cmd`` is ``None`` and no flag-only path is selected
(``reset``, ``repeat``, or ``copy_mode_cmd``).

## In other ports

### Send keystrokes to a pane

- Ruby: [`LibTmux::Pane#send_keys`](/en/ruby/latest/reference/libtmux-pane-send_keys/) (method)
- Lua: [`libtmux.Pane:send_keys`](/en/lua/latest/reference/libtmux-pane-send_keys/) (method)
- TypeScript: [`pane.Pane.sendKeys`](/en/ts/latest/reference/pane-pane-sendkeys/) (method)
- Rust: [`pane.Pane.send_keys`](/en/rs/latest/reference/pane-pane-send_keys/) (method)
- Go: [`tmux.Pane.SendKeys`](/en/go/latest/reference/tmux-pane-sendkeys/) (method)
- C#: [`LibTmux.Pane.SendKeysAsync`](/en/csharp/latest/reference/libtmux-pane-sendkeysasync/) (method)
- C++: [`libtmux::Pane::send_text`](/en/cxx/latest/reference/libtmux-pane-send_text/) (method)
- Swift: [`Server.sendKeys(_:to:literally:)`](/en/swift/latest/reference/server-sendkeys(_-to-literally-)/) (method)
- Kotlin: [`io.github.libtmux.kotlin.Pane.sendKeys`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-pane-sendkeys/) (method)
- Scala: [`io.github.libtmux.scaladsl.Pane.sendKeys`](/en/scala/latest/reference/io-github-libtmux-scaladsl-pane-sendkeys/) (method)
