Forked from amunchet/noVNCCopyPasteProxmox.user.js
Last active
April 21, 2023 12:09
-
-
Save PJB3005/fa1b3278b7d06712ca5de512717c3ddb to your computer and use it in GitHub Desktop.
noVNC Paste as keyboard
This file contains 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
// ==UserScript== | |
// @name noVNC Paste as keyboard | |
// @namespace http://tampermonkey.net/ | |
// @version 0.3 | |
// @description Pastes text into a noVNC window by typing key binds. Useful if you need to dump an SSH public key into a system over only VNC or something. Paste the text to be pasted into NoVNC's clipboard window, then activate the script paste button | |
// @author Chester Enright, Pieter-Jan Briers | |
// @match https://console.cp4staging.be/* | |
// @match https://console.level27.eu/* | |
// @grant GM_registerMenuCommand | |
// @grant GM_log | |
// ==/UserScript== | |
const delay = 1; | |
GM_log("noVNC Paste as keyboard"); | |
GM_registerMenuCommand("Paste", function(event) { | |
let text = document.getElementById("noVNC_clipboard_text").value.trim(); | |
let el = document.querySelector("canvas"); | |
setTimeout(() => { | |
for (let i = 0; i < text.length; i++) { | |
let x = text[i]; | |
let needs_shift = x.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/); | |
let evt; | |
if (needs_shift) { | |
evt = new KeyboardEvent("keydown", {keyCode: 16}); | |
el.dispatchEvent(evt); | |
evt = new KeyboardEvent("keydown", {key: x, shiftKey: true}); | |
el.dispatchEvent(evt); | |
evt = new KeyboardEvent("keyup", {keyCode: 16}); | |
el.dispatchEvent(evt); | |
} else { | |
evt = new KeyboardEvent("keydown", {key: x}); | |
} | |
el.dispatchEvent(evt) | |
} | |
}, delay) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment