sagar sagar - 11 days ago 5
Python Question

how to send F2 key to remote host using python

I have to send F2 key to telnet host. How do I send it using python...using

getch()
I found that the character
<
used for the F2 key but when sending
>
, its not working. I think there is a way to send special function keys but I am not able to find it. If somebody knows please help me. Thanks in advance

Answer

Extended keys (non-alphanumeric or symbol) are composed of a sequence of single characters, with the sequence depending on the terminal you have told the telnet server you are using. You will need to send all characters in the sequence in order to make it work. Here, using od -c <<< 'CtrlVF2' I was able to see a sequence of \x1b0Q with the xterm terminal.