Přeskočit na hlavní obsah

VNC Not Pasting Formatted Text into the Windows Clipboard – Auto-Convert to Plain Text

·3 min

When you copy formatted text (e.g. from Word or a web page) on a Windows machine and try to paste it through a VNC connection, the paste can silently fail or transfer nothing at all. The fix is to automatically strip formatting from the clipboard content using AutoHotkey, so only plain text ever gets shared with the VNC session.

The Problem #

Sharing the clipboard between a local Windows machine and a remote VNC session is a common way to move text into a remote desktop — you copy something locally, and the VNC client forwards the clipboard content to the remote side so you can paste it there (and vice versa).

This works fine for plain text, but breaks down as soon as the clipboard contains formatted content — RTF or HTML, which is exactly what ends up on the clipboard when you copy from Word, Outlook, or most web pages. Many VNC clients only forward the plain-text representation of the clipboard, but some sources don’t even populate that representation correctly, or the client picks the wrong clipboard format entirely. The result is that the paste either does nothing, or only part of the text arrives on the remote side.

There’s no reliable per-connection setting to force this — the practical fix is to make sure the Windows clipboard never holds formatted content in the first place, so there’s nothing for the VNC client to get wrong.

Solution: Auto-Convert the Clipboard to Plain Text #

The idea is to run a small background utility on the Windows machine that watches for clipboard changes and, whenever new content appears, immediately overwrites it with its plain-text equivalent. That way, by the time the VNC client reads the clipboard, only plain text is present — regardless of where the content was originally copied from.

AutoHotkey (v2) can do this in a few lines, using OnClipboardChange as a callback that fires whenever the clipboard content changes:

#Requires AutoHotkey v2.0

OnClipboardChange(ClipChanged)

ClipChanged(Type) {
    if (Type = 1) {
        OnClipboardChange(ClipChanged, 0)
        
        ToolTip "Clipboard changed, converting..."
        SetTimer () => ToolTip(), -1000
        
        text := A_Clipboard
        A_Clipboard := ""
        Sleep 100
        A_Clipboard := text
        
        OnClipboardChange(ClipChanged, 1)
    }
}

The trick is the line A_Clipboard := A_Clipboard. Reading A_Clipboard returns the clipboard’s plain-text representation; assigning it back to A_Clipboard replaces the entire clipboard content (including any RTF/HTML formats) with just that plain text. The Type = 1 check ensures this only runs when actual text was copied (not, say, a file or an image).

Save the script as, for example, C:\Users\<username>\autohotkey\clipboard.ahk and run it with a double-click. From then on, whatever you copy — even rich text from Word or a browser — will be reduced to plain text before your VNC client ever sees it, so pasting into the remote session works reliably.

Running It Automatically at Windows Startup #

Since the script needs to be running whenever you might use VNC, it makes sense to start it automatically when you log in.

Option 1 – Startup Folder (Simplest) #

  1. Press Win + R, type shell:startup, and hit Enter — this opens the Startup folder for the current user.
  2. Locate the clipboard.ahk file.
  3. Right-click it and choose Create shortcut.
  4. Move the shortcut into the opened Startup folder.

The next time you log into Windows, the script will start automatically in the background (it only runs in the system tray, no window opens).

Option 2 – Task Scheduler (More Reliable, Starts Earlier) #

  1. Open Task Scheduler.
  2. Choose Create Task (not Basic Task, for more options).
  3. Trigger: At log on.
  4. Action: Start a program — path to AutoHotkey.exe (or AutoHotkey64.exe), argument: path to the script (C:\Users\<username>\autohotkey\clipboard.ahk).
  5. On the Conditions tab, disable “Start only if on AC power” if you’re using a laptop.

For a simple clipboard script like this one, Option 1 is sufficient — it’s the fastest and least error-prone.