Skip to content

Instantly share code, notes, and snippets.

@juliobetta
Forked from byjg/NoVNC_Paste.js
Created December 12, 2017 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliobetta/9361c44b09921057f447e0c6bcf52dd1 to your computer and use it in GitHub Desktop.
Save juliobetta/9361c44b09921057f447e0c6bcf52dd1 to your computer and use it in GitHub Desktop.
How to Paste code to NoVNC.
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
window.sendString = function (str) {
f(str.split(""));
function f(t) {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);
if (needs_shift) {
rfb.sendKey(XK_Shift_L,1);
}
rfb.sendKey(code,1);
rfb.sendKey(code,0);
if (needs_shift) {
rfb.sendKey(XK_Shift_L,0);
}
if (t.length > 0) {
setTimeout(function() {f(t);}, 10);
}
}
}
})();
# Minified Version:
(function(){window.sendString=function(a){function b(c){var d=c.shift(),g=d.charCodeAt(),h=d.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);h&&rfb.sendKey(XK_Shift_L,1),rfb.sendKey(g,1),rfb.sendKey(g,0),h&&rfb.sendKey(XK_Shift_L,0),0<c.length&&setTimeout(function(){b(c)},10)}b(a.split(""))}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment