How can I get Linux to interpret keyboard charaters properly?
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)?
Solution 1:
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
Solution 2:
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
Solution 3:
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.