Last active
January 23, 2025 14:42
-
-
Save stil/54052d846c9e77e9da4f79af4c831bf5 to your computer and use it in GitHub Desktop.
Auto type in noVNC (Proxmox)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const text = prompt("Enter text to type:"); | |
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
const input = document.getElementById("noVNC_keyboardinput"); | |
const keydown = (key) => input.dispatchEvent(new KeyboardEvent("keydown", { key })); | |
for (let i = 0; i < text.length; i++) { keydown(text[i]); await sleep(50); } | |
})(); |
Here's a minified bookmarklet based on @rmb122 's answer
javascript:(function(){var e,t,n,a,i,l,o="",r="100",s=-1,p="00novnccustompastetool0947-maindiv",u="00novnccustompastetool0947-textinput",d="00novnccustompastetool0947-numinput";function c(e){e.preventDefault();var t=document.getElementById(p);document.body.removeChild(t)}let y=document.querySelector("iframe").contentDocument.getElementById("noVNC_keyboardinput"),m=e=>y.dispatchEvent(new KeyboardEvent("keydown",{key:e}));function $(){!(++s>=o.length)&&(!function e(t){if("\r"!==t){if(""===t){m("Tab");return}if("\n"===t){m("Enter");return}m(t)}}(o[s]),setTimeout($,r))}(e=document.createElement("div")).id=p,e.style.position="fixed",e.style.zIndex="9999999999",e.style.backgroundColor="rgb(221 221 221 / 90%)",e.style.top="0",e.style.left="0",e.style.right="0",e.style.padding="8px",e.style.height="168px",e.innerHTML="<b>Paste your text</b><br>Note: Use your mouse for copying and pasting because the KVM console snatches all input and this is the only sane work-around.<br>",(t=document.createElement("textarea")).id=u,t.onkeydown=function e(t){t.preventDefault()},t.style.display="block",t.style.width="100%",t.style.marginBottom="8px",(n=document.createElement("label")).innerHTML="Per-key delay in ms: ",n.title="Sending keys too fast can cause issues (such as skipped keys); the delay helps alleviate this.",(a=document.createElement("input")).title=n.title,a.setAttribute("type","number"),a.setAttribute("min","1"),a.setAttribute("max","100000"),a.value=r,a.id=d,(i=document.createElement("button")).innerText="Paste",i.onclick=function e(t){if(t.preventDefault(),o=document.getElementById(u).value,!(r=Number(document.getElementById(d).value)))return alert("Cannot proceed: delay number is invalid."),c();c(t),setTimeout($,500)},i.style.margin="8px",(l=document.createElement("button")).innerText="Cancel",l.onclick=c,e.append(t),e.append(n),e.append(a),e.append(document.createElement("br")),e.append(l),e.append(i),document.body.append(e)})();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By integrating the functionality from https://github.com/aggregate1166877/noVNC-Paste-Tool/blob/primary/paste-tool.js, now we can paste text through a nice GUI.😎