Created
May 25, 2016 20:41
-
-
Save trushkevich/7e1ac52dc127c8276acd96fca3d72bca to your computer and use it in GitHub Desktop.
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
// https://www.digitalocean.com/community/questions/why-i-cannot-use-in-ubuntu-12-10-console-copy-and-paste | |
var sendString = (function(rfb, force, sendDelay) { | |
sendDelay = sendDelay || 25; | |
var _q = []; | |
var _qStart = function() { | |
var chr = _q.shift(); | |
if (chr) { | |
rfb.sendKey(chr); | |
setTimeout(_qStart, sendDelay); | |
} | |
}; | |
var _qStop = function() { _q.length = 0; }; | |
var fn = function sendString(str) { | |
_qStop(); | |
str = str || ''; | |
var chr; | |
for (var i=0; i < str.length; i++) { | |
chr = str[i].charCodeAt(); | |
_q.push(chr); | |
} | |
_qStart(); | |
}; | |
if (rfb.sendString && true !== force) { | |
console.warn('rfb.sendString not installed because it already exists. Use force if you\'d like'); | |
} | |
else { | |
rfb.sendString = fn; | |
} | |
return fn; | |
})(rfb); | |
// sendString('test') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment