69

On the tmux man page I found no reference to how it names keys.

For example, to send ctrl + r to tmux you would do:

tmux send-keys C-r

and to send the esc key you do

tmux send-keys Escape

Is there a list which maps keyboard keys to how tmux sendkeys expects you to name them? I have a feeling that I missed a memo that its using some-long-forgotten-program's syntax for convenience.

Note, this is nothing to do with key bindings.

tshepang
  • 12,111
  • 21
  • 91
  • 136
xxjjnn
  • 14,591
  • 19
  • 61
  • 94

1 Answers1

80

The key names used by send-keys are the same ones that bind-key uses.
From the Key Bindings section of the tmux manpage:

When specifying keys, most represent themselves (for example ‘A’ to ‘Z’). Ctrl keys may be prefixed with ‘C-’ or ‘^’, and Alt (meta) with ‘M-’. In addition, the following special key names are accepted: Up, Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape, F1 to F20, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab.

Although they are not listed in the man page, there are also special names for keypad-specific keys: KP0 through KP9, KP/, KP*, KP-, KP+, KP., and KPEnter.

Several of the more cryptic key names (BTab, IC, DC, NPage, PPage) probably come from the terminfo library.

Emacs shares the convention of using C- and M- prefixes to indicate modifiers (I would not be surprised if there were earlier uses of this convention).

dcoles
  • 3,785
  • 2
  • 28
  • 26
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
  • 2
    is there a way to escape these binded keys? Say I want to send the literal string `enter` - what send-keys do is to send the named key "Enter" – Itamar Katz Jul 08 '15 at 11:01
  • 7
    @ItamarKatz: Use the `-l` (“literal”) flag: `send-keys -l Enter` will send the five letters: `E` `n` `t` `e` `r` (*tmux* 1.7+; for prior versions, break them up a bit: e.g. `send-keys E nter`). – Chris Johnsen Jul 08 '15 at 22:36
  • 8
    If you want to send a command and press enter, using space to separate them: `send-keys "ls" Enter` – diabloneo Dec 08 '15 at 03:31
  • 2
    How about sending `CTRL + C` to terminate whatever runing in tmux? – weefwefwqg3 Sep 25 '18 at 01:55
  • @weefwefwqg3 `tmux send-keys -t $PANE_ID C-c` – dza Dec 10 '22 at 02:27