Copy from Remote Desktop
This section presents sample Javascript code to implement copy-paste from a remote
virtual machine to the local client console.
Prerequisite
: Enable clipboard copy from the remote to local
client.After copy from the remote desktop, clipboard
data becomes available after the mouse cursor is no longer focused on the remote
desktop.
To implement remote copy, add this Javascript
code as a script to existing HTML console code:
<script> $(function() { var container = $("#container"); var wmks = WMKS.createWMKS("container", {}); wmks.register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(evt, data) { switch (data.state) { case WMKS.CONST.ConnectionState.CONNECTING: console.log("The console is connecting"); break; case WMKS.CONST.ConnectionState.CONNECTED: console.log("The console has been connected"); // need to send grab first, bind on the canvas element $("#mainCanvas").focus(function() { wmks.grab(); }); $("#mainCanvas").blur(function() { wmks.ungrab(); }); break; case WMKS.CONST.ConnectionState.DISCONNECTED: console.log("The console has been disconnected"); break; } }); wmks.register(WMKS.CONST.Events.ERROR, function(evt, data) { console.log("Error: " + data.errorType); }); wmks.register(WMKS.CONST.Events.COPY, function(evt, data) { // here is the remote clipboard data: console.log(evt, data); }); wmks.connect("wss://testurl"); }); </script>
Make sure the remote desktop has already
enabled clipboard feature. Before ungrab, a grab event is necessary. You can get remote
clipboard data from the server after sending ungrab.