Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the F1-F12 keys to switch screens in gnu screen in cygwin when connecting via SSH?

I'm connecting to a desktop running cygwin via SSH from the terminal app in Mac OS X. I have already started screen on the cygwin side and can connect to it over the SSH session. Furthermore, I have the following in the .screenrc file:

bindkey -k k1 select 1  #  F1 = screen 1
bindkey -k k2 select 2  #  F2 = screen 2
bindkey -k k3 select 3  #  F3 = screen 3
bindkey -k k4 select 4  #  F4 = screen 4
bindkey -k k5 select 5  #  F5 = screen 5
bindkey -k k6 select 6  #  F6 = screen 6
bindkey -k k7 select 7  #  F7 = screen 7
bindkey -k k8 select 8  #  F8 = screen 8
bindkey -k k9 select 9  #  F9 = screen 9
bindkey -k F1 prev      # F11 = prev
bindkey -k F2 next      # F12 = next

However, when I start multiple windows in screen and attempt to switch between them via the function keys, all I get is a beep.

I have tried various settings for $TERM (e.g. ansi, cygwin, xterm-color, vt100) and they don't really seem to affect anything.

I have verified that the terminal app is in fact sending the escape sequence for the function key that I'm expecting and that my bash shell (running inside screen) is receiving it. For example, for F1, it sends the following (hexdump is a perl script I wrote that takes STDIN in binmode and outputs it as a hexadecimal/ascii dump):

% hexdump
[press F1 and then hit ^D to terminate input]
00000000:  1b4f50                               .OP

If things were working correctly, I don't think bash should receive the escape sequence because screen should have caught it and turned it into a command.

How do I get the function keys to work?

like image 426
Mikey Avatar asked Jan 11 '11 02:01

Mikey


2 Answers

If you have a more bizarre setup (e.g. Windows -> PuTTY -> Linux) where the standard bindkey -k solution doesn't quite work right, you can use the showkey command:

showkey -a

to find the mapping from keystrokes to key codes. In my particular case, putting these in ~/.screenrc did the trick:

bindkey "^[[11~" select 1
bindkey "^[[12~" select 2
bindkey "^[[13~" select 3
bindkey "^[[14~" select 4
bindkey "^[[15~" select 5
bindkey "^[[17~" select 6
bindkey "^[[18~" select 7
bindkey "^[[19~" select 8
bindkey "^[[20~" select 9
bindkey "^[[21~" select 10
bindkey "^[[23~" select 11
bindkey "^[[24~" select 12
like image 181
Mr Fooz Avatar answered Sep 20 '22 11:09

Mr Fooz


With a great deal of experimentation, I was able to get it to work by adding the following lines to my .screenrc:

terminfo * k1=\EOP
terminfo * k2=\EOQ
terminfo * k3=\EOR
terminfo * k4=\EOS
terminfo * k5=\E[15~
terminfo * k6=\E[17~
terminfo * k7=\E[18~
terminfo * k8=\E[19~
terminfo * k9=\E[20~
terminfo * F1=\E[23~
terminfo * F2=\E[24~
like image 34
Mikey Avatar answered Sep 24 '22 11:09

Mikey