为SolusVM的noVNC增加粘贴功能 - 技术文档

  1. 门户首页
  2. 技术文档

为SolusVM的noVNC增加粘贴功能

在 SolusVM 的主控目录的:

/usr/local/solusvm/www/admincp/include/util.js
/usr/local/solusvm/www/include/util.js

增加以下内容:

function paste() {
    return !(function() {
        var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
        var o = [];
        for (let letter of t) {
            o.push(letter);
            console.log(letter);
        }

        function f() {
            var character = o.shift();
            var i = [];
            var code = character.charCodeAt();
            var needs_shift = "!@#$%^&*()_+{}:"<>?~|".indexOf(character) !== -1
            var shift = XK_Shift_L; // To help with minification             
            if (needs_shift) {
                rfb.sendKey(shift, 1);
            }
            rfb.sendKey(code, 1);
            rfb.sendKey(code, 0);
            if (needs_shift) {
                rfb.sendKey(shift, 0);
            }
            if (o.length > 0) {
                setTimeout(f, 10);
            }
        }
        f();
    })();
}
window.onload = function() {
    addbutton = document.getElementById('noVNC_buttons');
    addbutton.innerHTML += ('');
};