Search code examples
bashunixexpect

Send INSERT and F12 in expect script


I know that in order to send return in an expect script I do something like this:

send -- "\r"

What is the send command for the INSERT and F12 keys? I've looked online and cannot find it anywhere.


Solution

  • I have to say the initially accepted answer is not correct because

    1. The real char sequence is not the same for different terminal types;
    2. send -- "[2~" is wrong because
      1. [ in Tcl has special meaning (command substitution) so it should be backslash-escaped;
      2. The ESC char (\E as in infocmp's output) is missing;

    The correct way:

    set kf12 [exec tput kf12]
    set kins [exec tput kich1]
    ... ...
    send $kf12
    

    If you need to manually specify the TERM type, use tput -T:

    • -Ttype

      indicates the type of terminal. Normally this option is unnecessary, because the default is taken from the environment variable TERM. If -T is specified, then the shell variables LINES and COLUMNS will also be ignored.

    For the magic strings kf12 and kich1, search in the terminfo manual page.