Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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(""))}})();
@byjg

This comment has been minimized.

Copy link
Owner Author

byjg commented Oct 12, 2017

I started digging into the code following the forum https://www.digitalocean.com/community/questions/copy-and-paste-into-console and https://gist.github.com/croepha/7b53f211ae4be3c526c3.

The changes I did are:

  • Support A-Z uppercase characters;
  • The RFB.messages.keyEvent() changed and now requires rfb._sock. So, I simply change it to rfb.sendKey();
  • Remove the prompt and added the sendString() method;

I successfully tested it on:

  • EMBRATEL Cloud Service;
  • Digital Ocean.
  • Vultr;

Usage:

Open the developer tool box and paste the JavaScript above in the "console".

To send a string use:

sendString('string to be typed');

Let me know if it works

@blondie63

This comment has been minimized.

Copy link

blondie63 commented Mar 11, 2018

I've to open a console on which window?
I'm unable to open chrome console for DigitalOcean window console..

@katahdin0

This comment has been minimized.

Copy link

katahdin0 commented Mar 17, 2018

how does one use this ? maybe a set of "for-dummies" instruction might be useful. thanks.

@NathanUrwin

This comment has been minimized.

Copy link

NathanUrwin commented Sep 5, 2018

@blondie63 Try the CTRL+SHIFT+I shortcut if right-clicking is not available

@katahdin0 Read byjg's comment...

@byjg Worked great for me on Vultr!

@rlazoryshchak

This comment has been minimized.

Copy link

rlazoryshchak commented Jan 22, 2019

Solution doesn't work for characters like !@#

@n1rna

This comment has been minimized.

Copy link

n1rna commented Jan 8, 2020

<3

@byjg

This comment has been minimized.

Copy link
Owner Author

byjg commented Jan 8, 2020

@blondie63 Try the CTRL+SHIFT+I shortcut if right-clicking is not available

@katahdin0 Read byjg's comment...

@byjg Worked great for me on Vultr!

I did not watching this gist. Thank you for the information. CTRL+SHIFT+I or F12 could help as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.