# libtmux.Pane.send_keys

- **Module:** libtmux.Pane
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/pane.py#L694
- **Page:** https://libtmux.org/reference/py/libtmux-pane-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`` 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

- `self`
- `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).
- `copy_mode_cmd` (str | None) — Send a command to copy mode instead of keys (``-X`` flag).
When set, *cmd* is ignored.
- `repeat` (int | None) — Repeat count for the key (``-N`` flag).
- `expand_formats` (bool | None) — Expand tmux format strings in keys (``-F`` flag).
- `hex_keys` (bool | None) — Send keys as hex values (``-H`` flag).
- `target_client` (str | None) — Specify a target client (``-c`` flag). Requires tmux 3.4+.
- `key_name` (bool | None) — Handle keys as key names (``-K`` flag). Requires tmux 3.4+.

## Raises

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

## Example

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

## Example

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

## Example

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

## Example

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

## Example

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

```python
>>> pane.send_keys(reset=True)
```
