-
-
Save byjg/a6378edb420a1c654c5f27bb494ca1c8 to your computer and use it in GitHub Desktop.
// 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(""))}})(); |
I've to open a console on which window?
I'm unable to open chrome console for DigitalOcean window console..
how does one use this ? maybe a set of "for-dummies" instruction might be useful. thanks.
@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!
Solution doesn't work for characters like !@#
<3
@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.
Super @byjg 👏
Two small changes:
- Added pressOnly as pres/release generates echo in my test
- Added XK_Shift_L constant
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
const XK_Shift_L = 65505; // https://docs.rs/x11-dl/1.0.1/x11_dl/keysym/constant.XK_Shift_L.html
window.sendString = function (str, pressOnly) {
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);
!pressOnly && rfb.sendKey(code,0);
if (needs_shift) {
rfb.sendKey(XK_Shift_L,0);
}
if (t.length > 0) {
setTimeout(function() {f(t);}, 10);
}
}
}
})();
Thank you for share it @gbrian
Thank you! It's working for me. only I changed characters from = to +, 2 -> @ ...
Thank you @Girevik1
Thank you for your solution , saved my day . Just one small issue , if I try to paste characters like !@#$%^&*()_+ it actually prints 1234567890-= . I was testing on firefox , Ubuntu OS .
Glad that helps you. These characters should be handled by this:
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);
if (needs_shift) {
rfb.sendKey(XK_Shift_L,1);
}
It means, should "press" SHIFT and the key.
This code doesn't support new lines
Did you try:
sendString("mychars\r\nother chars"); # Maybe your client accepts \r\n as new line.
Did you try:
sendString("mychars\r\nother chars"); # Maybe your client accepts \r\n as new line.
Yup, tried \r
, \n
, \r\n
.
And even tried rfb.sendKey(13, true)
. None worked, it feels like noVNC
don't accept new lines in this function or something.
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:
I successfully tested it on:
Usage:
Open the developer tool box and paste the JavaScript above in the "console".
To send a string use:
Let me know if it works