It's not possible? Says who?

Using Ctrl+Tab in GNU Screen over PuTTY

with 6 comments

Being used to hit Ctrl+Tab for switching between tabs in e.g. Firefox, Opera, Miranda, I also wanted to use it in GNU Screen.

After a short search, I found a blog post “How to use Ctrl-Tab in GNU Screen” with a solution for xterm.

However, I use PuTTY which doesn’t transmit anything when you press Ctrl+Tab. But it’s open source, so I grabbed a copy of the 0.60 sources and patched putty\WINDOWS\WINDOW.C (using the key codes from Mikael Ståldal’s blog post):

diff -u -r putty-src.orig\WINDOWS\WINDOW.C putty\WINDOWS\WINDOW.C
--- putty-src.orig\WINDOWS\WINDOW.C	Sun Feb 25 00:50:24 2007
+++ putty\WINDOWS\WINDOW.C	Fri Apr 10 15:24:54 2009
@@ -3979,6 +3979,14 @@
 	    *p++ = 0;
 	    return -2;
+	if (wParam == VK_TAB && shift_state == 2) {	/* Ctrl-Tab */
+	    p += sprintf((char *) p, "\x1B[27;5;9~");
+	    return p - output;
+	}
+	if (wParam == VK_TAB && shift_state == 3) {	/* Ctrl-Shift-Tab */
+	    p += sprintf((char *) p, "\x1B[27;6;9~");
+	    return p - output;
+	}
 	if (wParam == VK_TAB && shift_state == 1) {	/* Shift tab */
 	    *p++ = 0x1B;
 	    *p++ = '[';

Then I recompiled PuTTY using Visual C++ Express and added the following lines to ~/.screenrc on my Linux box:

bindkey "^[[27;5;9~" next               # Ctrl-Tab
bindkey "^[[27;6;9~" prev               # Ctrl-Shift-Tab

And now, finally, I can use Ctrl+Tab in GNU Screen over PuTTY.

I don’t know whether this is a good way to do it. If you know a more correct way, please share your knowledge.

Written by johnLate

April 10th, 2009 at 5:48 pm

Posted in Uncategorized

6 Responses to 'Using Ctrl+Tab in GNU Screen over PuTTY'

Subscribe to comments with RSS or TrackBack to 'Using Ctrl+Tab in GNU Screen over PuTTY'.

  1. Thanks for this write up, I was wondering if anyone had encountered this before.

    I was curious though, any idea what the proper key codes should be to have vim recognize the key-presses as ” and ” respectively?


    26 Apr 09 at 06:48

  2. I can’t quite get this working… I recompiled putty without a hassle but screen doesn’t seem to be picking up the keybinding.

    Pressing ctrl-tab at a terminal in putty either within a screen session or at a bare terminal yields this output:

    me@host ~ $ 7;5;9~

    It looks like it’s sending the right char sequence but screen isn’t picking it up. I’ve tried using “^[[27;5;9~” as a straight text string and replacing ^[ with the actual escape character (ctrl-v, esc) & had no luck.

    Got any advice??


    22 Oct 09 at 04:48

  3. In your .screenrc, you enter bare text, no escape character. What is the OS on the ssh server? What is your $TERM?

    As a workaround, you could try to find the key code for F11 and F12 in your Putty sources, if you don’t use those keys for anything else, and replace “\x1B[27;5;9~” and the other one with the found key codes. Then recompile PuTTY and add “bindkey -k F1 prev” and “bindkey -k F2 next” to your “.screenrc”. (-k F1 is F11; NOT -k F11).


    22 Oct 09 at 07:27

  4. Would it be possible for you to post or send me a copy of your recompiled putty exe?



    30 Apr 10 at 00:29

  5. I’m sorry. I do not intend to redistribute modified PuTTY versions. Also I am currently using an unmodified PuTTY version and do not have Visual Studio installed.


    1 May 10 at 02:09

  6. thanks a lot. it worked.


    12 Nov 10 at 02:01

Leave a Reply