41

I recently started renting space on a remote server so that I could work on a project. I found that a relatively painless way to access it on a windows machine is through PuTTY. However, there is one thing that has always irked me when using it: for seemingly no reason random characters are sometimes inserted at the cursor.

Most of the time it is just a single tilde, but rarely it spits out what looks like some escape sequence ([[^8 or the like). It will only occur when I am focused on the window, whether I am typing or 20 feet away from the keyboard. If left for long enough, it will spit tildes at random intervals (average is about 1 minute).

Finally, this behavior seems to be inconsistant when running programs such as nano or the mysql interface: in nano, instead of inserting tildes, it will set marks (ctrl-^); in mysql, lines will become un-editable.

My question is this: Has anyone else experienced this sort of behavior in PuTTY? And if so, what can be done to prevent/correct this behavior?

9
  • Does your computer also do this if you leave open a random program on your host for a few hours, like notepad?
    – cutrightjm
    Jan 29, 2014 at 6:08
  • @ekaj No, only in PuTTY. And aparantly PuTTY based programs like MobaXterm (I downloaded the portable version to test) EDIT: only during an SSH session in Moba Jan 29, 2014 at 6:39
  • Hmm. Are you sure it's not pretty close to periodic, like always 55-65 seconds while putty is entirely idle? If it is, it might be a "keep-alive" activity, either from the server end or maybe putty. Have a look at things found under a search "alive" in putty help. Maybe these will be helpful: superuser.com/questions/94436/… unix.stackexchange.com/questions/6105/…
    – mgkrebbs
    Jan 29, 2014 at 8:54
  • @mgkrebbs Sometimes it seems periodic, but it occasionally won't occur for about 5 to 6 minutes, then go right back to seeming periodic. Regarding the keep-alive idea, if that is the case, It seems to be isolated to the client side because if I start an ssh session from a linux machine in native terminal, all is well. I did see that first link when I was asking the question, and tried changing the terminal type to "linux", but that didn't seem to make any noticable difference. Jan 29, 2014 at 13:10
  • I've been experiencing this issue as well. It shows up when I'm using Putty, Kitty and even MobaXterm.
    – Attilah
    Apr 27, 2014 at 7:14

11 Answers 11

57

I had the same problem with PuTTY and found that is was being caused by an application I have called "caffeine" which effectively presses the F13 key every minute to stop the screen saver from being activated (group policies prevent me from changing screen saver timeout on my machine). Disabling the application solved me problem.

3
  • 3
    I did have caffeine installed at the time! It all makes sense now... Thanks Bruce! Jun 7, 2014 at 2:12
  • 3
    Doh, I should've suspected that. Killing Caffeine did the trick. PS: See my solution below to have Caffeine and Putty working together
    – shreyansp
    Oct 16, 2015 at 10:24
  • I had a signage app that did the same. Some [28~ appeared on the Terminal. Jan 18, 2019 at 10:28
20

If you prefer to have Putty and Caffeine running then follow these steps:

  1. Stop Caffeine
  2. Check the Caffeine readme.txt for the default key simulated - mine was F15
  3. Login to your remote terminal via Putty
  4. Start Caffeine (Tip: start Caffeine with short interval e.g 3 seconds).
  5. Bring the Putty session in focus.
  6. On your bash command prompt press Ctrl+V (This is required to get the special code for the key. e.g try Ctrl+V followed by F12)
  7. Wait for Caffeine to simulate the key
  8. The key code will be displayed on the command line (e.g F15 is ^[[28~, where ^[ is escape). Stop Caffeine
  9. Now you can bind this key to blank so that when Caffeine simulates it, it won't type ~
    • edit ~/.inputrc (create a new file if it doesn't exist)
    • add the line "\e[28~":""
  10. Start Caffeine
  11. Restart your terminal session
    • There should be no more random ~ when using the Putty terminal with that linux server
1
  • +1. I've expanded on this answer below (with explanation on why this wasn't the optimal answer for me) :) Apr 26, 2017 at 19:55
16

I found shreyansp's solution to be the most (but not quite) satisfactory one :)
Here's my attempt on improving that (of course YMMV). Hope this may be of use to those looking for a solution :)

My solution behaves as follows:

  • caffeine sends to Windows an appropriate Virtual-Key Code which:
    • prevents Windows from going to sleep or idle
    • does not otherwise generate any side-effects on Windows neither alone nor in combination (no Ctrl, Shift, Alt, Alt-Gr, Win, F1-F5, F10, etc.)
    • either is not sent to Putty or is ignored by Putty

TL;DR: My solution is applied between steps 2 and 3 (see below) with the -key:0E caffeine param:
Exit Caffeine & re-launch it with:
caffeine.exe 5 -key:0E (for easy testing)
caffeine.exe 50 -key:0E (for a mandatory screen saver set at 1 minute)

  • Launch read program on the remote host and watch how no keystrokes are received every 5 or 50 seconds.
  • Exit read with Ctrl+C

Shreyansp proposed a solution where a fix would be applied between steps 5 and 10 (see below).
The side-effect of that (on my config) was that, with each keystroke that putty forwarded from caffeine to the remote host:

  • it triggered a 'Reset scrollbar on keypress' (setting on Putty/Window page)
    which I would normally want, but only when I (the human) is pressing the key but not regularly by caffeine :)
  • readline/bash translated version of it (from '"\e[28~"' to '""' (blank key ?) caused the remote session interaction to hang for several seconds

In order to easily test the above, exit Caffeine & re-launch it with 5 seconds interval and Virtual-Key Code 07:
caffeine.exe 5 -key:07

  • Launch read program on the remote host and watch how keystrokes are received every 5 or 50 seconds.
  • Exit read with Ctrl+C

The keystroke 'pipeline', as I understand it:

  1. Caffeine sends a Virtual-Key Code to Windows
  2. Windows sends that Virtual-Key Code to Putty
  3. Putty does some 'translations'/'mappings' based on some session settings in:
    • Terminal/*
    • Window/*
  4. Putty sends the 'translated'/'mapped' key code to the remote host
  5. On the remote host, the 'terminal' program (e.g: $TERM=xterm, vt100, vt102, vt220, etc.) translates from the 'line protocol' into key codes.
  6. the readline library does some translations/mappings based on ~/.inputrc
  7. readline sends the Key Code to bash
  8. bash does some translations/mappings based on ~/.bashrc (based on the builtin bind command)
  9. bash or readline (not sure which one) sends the translated Key Code to nano (my text editor)
  10. This pipeline can get even longer by adding the screen program (which includes a $TERM=screen for step 5. and loops back again at step 6. to 10.)

Note: Once it gets to step 4., it becomes very difficult to precisely control the different layers of 'translations'/'mappings'. I would recommend avoiding that if you can.


Background:
I used caffeine.exe -key:07 for years before having to deal with a pfsense 2.3.3-RELEASE-p1 (based on FreeBSD 10.3-RELEASE).
Then, caffeine.exe -key:07 was received on the other side as ^[[28~ ... which seems to be mapped to Ctrl+^ (Set Mark) in Nano.
This was quite annoying (imagine someone pressing and keeping Shift Key while you move the text caret around in Notepad).

Previously, I did numerous customizations in Putty Settings, ~/.tcshrc, ~/.inputrc, ~/.bashrc, ~/.nanorc, ~/.screenrc to get what I consider basic functionality (Backspace, Delete, Home, End, PgUp, PgDown, Ctrl+Left, Ctrl+Right, Numpad 0-9, Numpad ./*-+) working consistently between bash/nano/screen.

Once I discovered this caffeine.exe -key:07 'bug', I didn't want to retrace that all over again :)


Tested on:
Windows 8.1 64-bit Enterprise (6.3.9600) / Putty 0.66 / pfsense 2.3.3-RELEASE-p1 (based on FreeBSD 10.3-RELEASE) / bash 4.4.12-release / nano 2.7.3 / screen 4.04.00


References:

2
  • On Windows 10 64-bit, the 0E key launches a print dialog.
    – MoshiBin
    Mar 29, 2020 at 7:20
  • @MoshiBin Good to know. What specific version of Win 10 (winver version) ? Any other other lucky Virtual-Key Code for your Win 10 ? May 6, 2020 at 14:28
1

This really does look like an escape sequence, or control character, which might explain why you don't see it in other programs like notepad.

I'm not quite sure which keys have to be pressed to get this output, but I'll play around a bit and try to find out. Can you name any other sequence shown? The behaviour of mysql and nano might just be another interpretation of the escape sequences that seem to get entered.

Finally, the question is what causes these key inputs. Do you, by any chance, use a laptop which e.g. automatically controls the backlight using some proprietary software? I've seen some weird preinstalled software actually emulating the keypresses instead of using the API. You might want to use something like inputlog on yourself.

3
  • I have since changed operating systems, first changing my dual Win-8.1 & Ubuntu to Ubuntu only, then to Mint, and finally to Arch. I have not experienced any similar problems, which leads me to believe that the problem was isolated to the manner in which Windows interacted with PuTTY. As for the cause of the key inputs, I would not be surprised if what you suggested was the case, however I did not use or notice any sort of automatic hardware control. If I still had those logs, I would post them. EDIT: If anyone else is experiencing this I encourage you to post this information. May 1, 2014 at 16:24
  • See also Gilles' answer in Why Putty inserting ~ into my Fedora bash shell, which nicely explains why one might only see the ~ (and hear a beeb) when actually something like \e[3~ is sent.
    – Arjan
    May 3, 2014 at 12:18
  • (As an aside: you might want to link to that post, as at first I figured seeing a single ~ would not indicate an escape sequence.)
    – Arjan
    May 3, 2014 at 12:24
1

The better solution is to configure the settings on your putty session so that Caffine does not interfere with it.

In Putty under Terminal Keyboard choose the SCO option. In Putty under Terminal Bell change action to None (to turn off the chime).

Caffine will still do it's thing and not bother your putty session. (I don't use Fn keys during a putty session so I don't know what happens if you do want to use Fn keys).

1

I use the -key:07 option on the commandline to launch caffiene.. Seems to stop the Putty problem.

Just put this in a bat file

caffeine.exe -key:07

2
  • I use 'caffiene.exe -key:07' as well at it served me well for years. However, since connecting to my pfSense (FreeBSD-based), this is received on the other side as ^[[28~ ... which seems to be mapped to Ctrl+^ (Set Mark) in Nano. This is quite annoying (imagine someone pressing and keeping Shift Key while you move the text caret around in Notepad). :) I'll have either find another key on caffeine side or do a custom mapping on the FreeBSD side. (see defs @ msdn.microsoft.com/en-us/library/windows/desktop/…) Apr 26, 2017 at 14:34
  • Switched to caffeine.exe -key:0E (see my answer below). Seems to work well with Windows (8.1 64-bit) and Putty happily ignores it :) Apr 26, 2017 at 19:13
1

The issue definitely is with the Caffeine application which sends a key to keep your system from going to sleep. I faced the same problem recently:

enter image description here

Clearly, the interval is an approx 1 minute. I went through some of the solutions listed above and tried them one followed by the next. The one which worked for me is quite simple:

  1. Close all running instances of Caffeine. [Go to the bottom right corner and find the Caffeine icon on your task bar. Right click to exit.]
  2. Go to command prompt [Windows+R --> cmd --> Enter] and traverse to the extracted folder say, C:\caffeine\ and run caffeine.exe with -key:07

    i.e. C:\caffeine\caffeine.exe -key:07

Now an instance of Caffeine should start and you should be able to find it on your task bar. Hover over it to see the message: caffeine: active [-key:07].

This should now have solved your problem. I see that my Putty and MobaXterm are functioning well as before without the tilde interference.

0

Someone on Cisco forums suggests to change the console speed parameter to solve this problem.

http://www.dslreports.com/forum/r27090677-HELP-Cisco-1800-garbled-output-in-putty

You've definitely tried all the variations of console speed in Putty as mentioned in 1 ?

Note: If the baud rate is set different than the default rate, odd characters are seen on CLI. Check table1 to set baud rates for different Confreg values.

1
  • 1
    Console speeds are for serial connections. He's referring to a SSH connection. While SSH does have a "Terminal Speed" setting...I've never actually seen this cause an issue.
    – Jared
    Apr 29, 2014 at 15:49
0

I also had the same problem and found that caffeine.exe was indeed the problem. At first I thought it could not be caused by caffeine.exe because I was using this for 2+ years on my old laptop. I tried changing caffeine.exe -useshift instead, but that sent ^C. Found another program, Mouse Jiggler, that keeps the screen saver away but does not send any Escape sequences in my Putty sessions anymore.

0

2017-09-20 : Solved the char injection by starting caffeine with «caffeine.exe -useshift -noicon» in task scheduler triggered at logon. No icon, no more injected chars in my mintty/bash sessions. That was so much annoying. Thanks everyone for your hints.

0

In the shortcut that starts Caffeine, add -STES to the command. That solved it for me using KiTTY (fork of PuTTY).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .