4

I am accessing a linux box via ssh using putty.

Key combinations work fine when I'm not running screen. However, Ctrl key combinations do not work under a screen session. In fact, a Ctrl-any key is registered the same as the same key without the Ctrl combination.

I know this by typing Ctrl-V and then a Ctrl-key combination to figure out what characters are sent to my terminal.

For example, Ctrl- (left arrow) gives me ^[[D on screen (screen256-color term). gives me the same result.

Weird thing is that Alt-key combinations work fine.

In particular, I would like to get the 'forward-word' and 'backward-word' key bindings working under screen.

I have tried modifying .inputrc to work with various terminals. As such, my .inputrc looks something like this:

$if term=xterm
    'xxx' : forward-word # xxx key gotten from Ctrl-V
    'xxx' : backward-word
$endif
$if term=screen-256color
...
...

I have also tried various terminals by setting the TERM of my bash profile, setting TERM on .screenrc, and setting the Putty keyboard terminal mappings. The obvious ones, linux and xterm, don't work. However, I haven't tried every permutation of settings for obvious reasons.

Additional info:

I stand corrected, arrow key combinations are the only combinations that do not work. The distro is RHEL 6.

.screenrc:

term xterm # tried other terms as well
shell -$SHELL # login shell to reload configs
caption string "%w"
hardstatus alwayslastline "%{b kw}%H %{r}%1` %{w}| %{g}%c %{w}| %{y}%d.%m.%Y %{w}| %{g}%l %{w}| %{-b kw}%u %-Lw%{= rW}%50> %n%f %t %{-}%+Lw%<"
vbell off
defscrollback 5000

Putty's default keyboard mode ESC [n~.

Taken from the putty manual: "In the default mode, labelled ESC [n~, the function keys generate sequences like ESC [11~, ESC [12~ and so on. This matches the general behaviour of Digital's terminals."

Interestingly, what's actually sent by Putty (by following the first answer on https://superuser.com/questions/342848/cant-get-keyboard-to-work-correctly-in-putty), is

^[0D : left-arrow
^[[D : Ctrl-{left-arrow}

Since the they are different, I guess putty isn't the issue then?

FWIW, I tried changing the Application Cursor key mode settings on Putty, but to no avail. I also tried using tmux, only to encounter the same issue.

  • If Ctrl+V doesn't act like V, then evidently some Ctrl+key combinations do work. Which ones don't work? Arrow keys? What distribution is this, what is present in /etc/screenrc and ~/.screenrc? what key combination does PuTTY send for the Ctrl+key combinations that don't work in screen? – Gilles Jun 29 '14 at 13:57
  • indeed it's only the arrow key combis that don't work. I've updated the post to provide the requested info. – grayskin Jun 30 '14 at 0:48
  • 1
    Did you ever find a solution? – Raj Jul 21 '15 at 6:58
3

In its default configuration, PuTTY sends cursor keys in normal mode, e.g., ^[OA while screen sets the cursor keys to application mode, e.g., ^[[A.

That is done by screen's sending the escape sequence to turn on the keypad (in termcap ks, terminfo smkx). That happens to turn on the application mode for both the numeric keypad and the cursor keys, because both are present in the ks/smkx capability. screen uses this capability if it is present, when initializing the terminal. screen also follows up by sending the string in the termcap CS capability if it is set, hinting that the original design was to use terminal descriptions where only the keypad was initialized by ks/smkx.

You notice this difference because your key bindings expect the strings sent by the cursor keys in normal mode. If you modified the terminal description for screen to omit the part which changes the cursor keys, you could continue to use those bindings.

For instance, you could do this:

infocmp screen >foo
vi foo

and change the assignment

smkx=\E[?1h\E=,

to

smkx=\E=,

then

tic foo

to compile the modified description. If you do this as your (non-root) user, tic will put the compiled description in your ~/.terminfo directory. There are drawbacks to this approach, and using tput to obtain key-binding information is preferable. But it is simple.

Further reading:

  • your answer is very interesting and verbose, but not that much practically applicable because one usually don't want to adapt screen to putty but the other way round..! – Gewure Feb 27 '18 at 0:34
1

I found this on another question after posting the bounty...

* Ctrl and arrow keys doesn't work in putty! What do I do?

putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for tmux to detect properly. To get ctrl keys right, change the terminfo settings so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux doesn't change the mode. For example with this line in .tmux.conf (assuming you have TERM set to xterm):

set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"

Note that this will only work in tmux 1.2 and above.

https://stuff.mit.edu/afs/athena/project/bsd/src/tmux-1.3/FAQ

  • tmux is not GNU screen, so this is not an answer to this question... – Wouter Verhelst Jan 16 '17 at 13:52

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.