From bdb12ce7cceb5e3c5cf5f8da9587894fce4e753c Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 28 Feb 2022 09:52:35 -0800 Subject: [PATCH] Added KVM key state command support --- meshdesktopmultiplex.js | 11 ++++++++--- public/scripts/agent-desktop-0.0.2.js | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/meshdesktopmultiplex.js b/meshdesktopmultiplex.js index 9fedec9c..c1f399f0 100644 --- a/meshdesktopmultiplex.js +++ b/meshdesktopmultiplex.js @@ -34,7 +34,7 @@ MNG_KVM_SET_DISPLAY = 12, MNG_KVM_FRAME_RATE_TIMER = 13, MNG_KVM_INIT_TOUCH = 14, MNG_KVM_TOUCH = 15, -MNG_KVM_CONNECTCOUNT = 16, +MNG_KVM_KEYSTATE = 16, MNG_KVM_MESSAGE = 17, MNG_ECHO = 21, MNG_JUMBO = 27, @@ -82,6 +82,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) { obj.lastData = null; // Index in the images table of the last image in the table. obj.lastDisplayInfoData = null; // Pointer to the last display information command from the agent (Number of displays). obj.lastDisplayLocationData = null; // Pointer to the last display location and size command from the agent. + obj.lastKeyState = null; // Pointer to the last key state command from the agent. obj.desktopPaused = true; // Current desktop pause state, it's true if all viewers are paused. obj.imageType = 1; // Current image type, 1 = JPEG, 2 = PNG, 3 = TIFF, 4 = WebP obj.imageCompression = 50; // Current image compression, this is the highest value of all viewers. @@ -178,7 +179,8 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) { if (obj.lastDisplayInfoData != null) { obj.sendToViewer(peer, obj.lastDisplayInfoData); } if (obj.lastDisplayLocationData != null) { obj.sendToViewer(peer, obj.lastDisplayLocationData); } if (obj.lastConsoleMessage != null) { obj.sendToViewer(peer, obj.lastConsoleMessage); } - + if (obj.lastKeyState != null) { obj.sendToViewer(peer, obj.lastKeyState); } + // Log joining the multiplex session if (obj.startTime != null) { var event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: peer.user ? peer.user._id : null, username: peer.user.name, msgid: 143, msgArgs: [obj.id], msg: "Joined desktop multiplex session \"" + obj.id + "\"", protocol: 2 }; @@ -788,7 +790,10 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) { break; case 15: // KVM_TOUCH break; - case 16: // MNG_KVM_CONNECTCOUNT + case 16: // MNG_KVM_KEYSTATE + // Store and send this to all viewers right away + obj.lastKeyState = data; + obj.sendToAllInputViewers(data); break; case 17: // MNG_KVM_MESSAGE // Send this to all viewers right away diff --git a/public/scripts/agent-desktop-0.0.2.js b/public/scripts/agent-desktop-0.0.2.js index 8ee6956e..6f73dea3 100644 --- a/public/scripts/agent-desktop-0.0.2.js +++ b/public/scripts/agent-desktop-0.0.2.js @@ -52,6 +52,10 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { obj.onRemoteInputLockChanged = null; obj.RemoteInputLock = null; + // Remote keyboard state + obj.onKeyboardStateChanged = null; + obj.KeyboardState = 0; // 1 = NumLock, 2 = ScrollLock, 4 = CapsLock + obj.ScreenWidth = 960; obj.ScreenHeight = 701; obj.width = 960; @@ -260,6 +264,10 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) { obj.TouchArray = {}; break; case 16: // MNG_KVM_KEYSTATE + if ((cmdsize != 5) || (obj.KeyboardState == view[4])) break; + obj.KeyboardState = view[4]; // 1 = NumLock, 2 = ScrollLock, 4 = CapsLock + if (obj.onKeyboardStateChanged) { obj.onKeyboardStateChanged(obj, obj.KeyboardState); } + console.log('MNG_KVM_KEYSTATE:' + ((obj.KeyboardState & 1) ? ' NumLock' : '') + ((obj.KeyboardState & 2) ? ' ScrollLock' : '') + ((obj.KeyboardState & 4) ? ' CapsLock' : '')); break; case 17: // MNG_KVM_MESSAGE var str = String.fromCharCode.apply(null, view.slice(4));