Copy and Paste on Proxmox VM

Published: (December 2, 2025 at 05:52 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Issue

Copy and paste does not work well on Proxmox KVM through the web UI.

Workaround

We created a script that simulates keyboard typing to paste data over the KVM console. Open Chrome DevTools, focus the console tab, and paste the following code:

function simulateKeyEvent(el, eventType, key, options = {}) {
  const evt = new KeyboardEvent(eventType, { key, ...options });
  el.dispatchEvent(evt);
}

const sendKey = (char) => {
  let capsLockOn = false;
  const SHIFT_NEEDED = /[A-Z!@#$%^&*()_+{}:"<>?~|]/;

  const canvas = document.querySelector("canvas");
  canvas.focus();

  if (char === '\n') {
    simulateKeyEvent(canvas, "keydown", "Enter");
    simulateKeyEvent(canvas, "keyup", "Enter");
  } else {
    const needsShift = SHIFT_NEEDED.test(char);
    const isUpperCase = char >= 'A' && char <= 'Z';

    if (needsShift) {
      simulateKeyEvent(canvas, "keydown", "Shift", { keyCode: 16 });
    }

    if (isUpperCase && capsLockOn) {
      simulateKeyEvent(canvas, "keydown", char.toLowerCase());
      simulateKeyEvent(canvas, "keyup", char.toLowerCase());
    } else {
      simulateKeyEvent(canvas, "keydown", char);
      simulateKeyEvent(canvas, "keyup", char);
    }

    if (needsShift) {
      simulateKeyEvent(canvas, "keyup", "Shift", { keyCode: 16 });
    }

    if (char === "CapsLock") {
      capsLockOn = !capsLockOn;
      console.log("Caps Lock state changed:", capsLockOn);
    }
  }
};

function cp(text) {
  let index = 0;

  function typeChar() {
    if (index < text.length) {
      sendKey(text[index]);
      index++;
      setTimeout(typeChar, 100); // Adjust delay as needed
    }
  }

  typeChar();
}

How to Use

  1. Click inside the Proxmox console UI to give it focus.
  2. In the DevTools console, run:
cp('mydata')

Replace 'mydata' with the text you want to paste. This method works even when you don’t have SSH access to the VM.

Back to Blog

Related posts

Read more »