Added KVM key state command support
Ylian Saint-Hilaire committed
Feb 28, 2022 at 09:52 UTC
bdb12ce7cceb5e3c5cf5f8da9587894fce4e753c
2 files changed
+16
-3
meshdesktopmultiplex.js
+8
-3
@@ -34,7 +34,7 @@ MNG_KVM_SET_DISPLAY = 12,
34
MNG_KVM_FRAME_RATE_TIMER = 13,
35
MNG_KVM_INIT_TOUCH = 14,
36
MNG_KVM_TOUCH = 15,
37
-MNG_KVM_CONNECTCOUNT = 16,
37
+MNG_KVM_KEYSTATE = 16,
38
MNG_KVM_MESSAGE = 17,
39
MNG_ECHO = 21,
40
MNG_JUMBO = 27,
@@ -82,6 +82,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) {
82
obj.lastData = null; // Index in the images table of the last image in the table.
83
obj.lastDisplayInfoData = null; // Pointer to the last display information command from the agent (Number of displays).
84
obj.lastDisplayLocationData = null; // Pointer to the last display location and size command from the agent.
85
+ obj.lastKeyState = null; // Pointer to the last key state command from the agent.
86
obj.desktopPaused = true; // Current desktop pause state, it's true if all viewers are paused.
87
obj.imageType = 1; // Current image type, 1 = JPEG, 2 = PNG, 3 = TIFF, 4 = WebP
88
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) {
179
if (obj.lastDisplayInfoData != null) { obj.sendToViewer(peer, obj.lastDisplayInfoData); }
180
if (obj.lastDisplayLocationData != null) { obj.sendToViewer(peer, obj.lastDisplayLocationData); }
181
if (obj.lastConsoleMessage != null) { obj.sendToViewer(peer, obj.lastConsoleMessage); }
181
-
182
+ if (obj.lastKeyState != null) { obj.sendToViewer(peer, obj.lastKeyState); }
183
+
184
// Log joining the multiplex session
185
if (obj.startTime != null) {
186
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) {
790
break;
791
case 15: // KVM_TOUCH
792
break;
791
- case 16: // MNG_KVM_CONNECTCOUNT
793
+ case 16: // MNG_KVM_KEYSTATE
794
+ // Store and send this to all viewers right away
795
+ obj.lastKeyState = data;
796
+ obj.sendToAllInputViewers(data);
797
break;
798
case 17: // MNG_KVM_MESSAGE
799
// Send this to all viewers right away
public/scripts/agent-desktop-0.0.2.js
+8
@@ -52,6 +52,10 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
52
obj.onRemoteInputLockChanged = null;
53
obj.RemoteInputLock = null;
54
55
+ // Remote keyboard state
56
+ obj.onKeyboardStateChanged = null;
57
+ obj.KeyboardState = 0; // 1 = NumLock, 2 = ScrollLock, 4 = CapsLock
58
+
59
obj.ScreenWidth = 960;
60
obj.ScreenHeight = 701;
61
obj.width = 960;
@@ -260,6 +264,10 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
264
obj.TouchArray = {};
265
break;
266
case 16: // MNG_KVM_KEYSTATE
267
+ if ((cmdsize != 5) || (obj.KeyboardState == view[4])) break;
268
+ obj.KeyboardState = view[4]; // 1 = NumLock, 2 = ScrollLock, 4 = CapsLock
269
+ if (obj.onKeyboardStateChanged) { obj.onKeyboardStateChanged(obj, obj.KeyboardState); }
270
+ console.log('MNG_KVM_KEYSTATE:' + ((obj.KeyboardState & 1) ? ' NumLock' : '') + ((obj.KeyboardState & 2) ? ' ScrollLock' : '') + ((obj.KeyboardState & 4) ? ' CapsLock' : ''));
271
break;
272
case 17: // MNG_KVM_MESSAGE
273
var str = String.fromCharCode.apply(null, view.slice(4));