I access a linux server shell via putty, but many of the keys I use do not translate across,
up, down, left and right all are seen as ^[[A, ^[[B, ^[[D and ^[[C;
But so is C-up, C-down, C-left and C-right.
And enter is seen as C-j (which move down to the next line),
and backspace is seen as C-h, which is backwards delete.

How can I stop these keys being translated into other keys (so I can, for example, configure C-h and backspace to perform two different functions) and what's doing this translation (Putty, the kernel, the shell)?

  • In your shell, what does echo $TERM return? Do you have a terminfo file on the server for that terminal type? Does PuTTY have a setting enabling you to change the TERM type? – dubiousjim Feb 18 '10 at 0:07
  • $TERM is 'vt100', which I do have a terminfo file for. I'm actually using PuttyTel, which is like PuttyCyg (it connects to a cygwin process) but I had the same problems running just vanilla Putty. Is it certain to be putty that isn't passing along my original keypresses? – CH2048 Feb 18 '10 at 0:14
  • Don't forget that some applications just don't support that at all. For example, bash and vim know about arrow keys, but sh and vi don't. – user1686 Feb 18 '10 at 14:32
  • Similar to superuser.com/questions/110622 (probably same questioner), superuser.com/questions/110248 (same questioner, closed), and superuser.com/questions/94436. – dubiousjim Feb 18 '10 at 23:22

Try changing $TERM to "xterm".

Try setting PuTTY's keyboard settings to "rxvt", "Esc[n~" and "Control-?".

What shell are you using? If it's Bash then there are some settings you might want to make in ~/.inputrc.

Keypress interpretation is affected by a combination of:

  • PuTTY - or other terminal emulator
  • The OS you're running the terminal emulator on
  • /etc/X11/xorg.conf - if you're using the X-Window system.
  • Bash/Readline via /etc/inputrc and ~/.inputrc - or similar features in other shells
  • terminfo or in some cases termcap
  • The $TERM variable
  • Probably something I'm forgetting

OK, So here's the solution I came up with - I ditched PuttyCyg and started using MinTTY. it seems to pass along alot more of my actual keys to the server. :>

To elaborate -
After seeing this blog post figured there was a good change Putty(Cyg) might actually need to be patched to do what I want, so I experimented with other terminal emulators that could interface with cygwin. MinTTY showed different codes when I used C-v to see what the server what seeing, including:
Different codes for C-(arrow key) than (arrow key),
C-M for Return, C-^ for C-Return,
also different codes for meta'd tab and backspace;
What this means is these keys now register as different, so can configure emacs to use them for different things e.g. C-M can be 'newline and indent', while C-^ is 'cua-set-rectangle-mode'. I've been trying to fix my SSHed emacs session for ages...
For more detail on emacs in particular, and keycodes in general, I also found this


Yeah, there are a lot of players determining how your keys are interpreted. If it's a remote system you're connecting to then PuTTY or whatever your terminal emulator is is a likely bottleneck---that is, if it's sending the same data for up and control-up, nothing you do downstream can recover the difference. This is true for each of the players, but I know most of the others to be configurable. I don't know how configurable your terminal emulator is. Some will, even if they're capable of seeing a difference between up and control-up, still send the same data to the processes they're connected to.

Are you running PuTTYTel in Windows? Then someone else will have to help you figure out how to get PuTTYTel to detect the difference between up and control-up, and send different data for each. I only know *nix.

What key is sent by return and by delete and so on are determined by what TERM your terminal emulator is set to be using. You should be able to use anything that you have a terminfo file for at the other end. On my machine, the terminfo file for vt100 says return should be a ^M, though, not a ^J. (Backspace in vt100 is ^H.) So I don't know how much you're going to be able to rely on this terminal emulator...

Backspace is also ^H in xterm. In other terminfo definitions it's ^?, that is 0x7f. For instance, that's true on the "linux" and "rxvt-unicode" terminfo definitions.

  • ^J is linefeed, but Bash/Readline will accept it as "accept-line" (aka return). – Paused until further notice. Feb 18 '10 at 15:12
  • Yeah, and you can make Bash/Readline accept almost anything as accept-line, if you like. – dubiousjim Feb 18 '10 at 17:04

The keypresses you want are not representable on a vt100. They simply cannot exist with that terminal type. Try setting emulation to xterm, or rxvt (if you use a terminal emulator that can do xterm emulation, it can even share mouse information with the application on the other end).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.