Keyboard mapping fix.

Ylian Saint-Hilaire committed Feb 28, 2022 at 12:32 UTC 22bf06837db4393cdb4ad3ef56f1b35a16da56fb
3 files changed +76 -41
meshdesktopmultiplex.js
+7 -6
@@ -34,8 +34,9 @@ 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_KEYSTATE = 16,
37 +MNG_KVM_CONNECTCOUNT = 16,
38 MNG_KVM_MESSAGE = 17,
39 +MNG_KVM_KEYSTATE = 18,
40 MNG_ECHO = 21,
41 MNG_JUMBO = 27,
42 MNG_GETDIR = 50,
@@ -790,15 +791,15 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) {
791 break;
792 case 15: // KVM_TOUCH
793 break;
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;
794 case 17: // MNG_KVM_MESSAGE
795 // Send this to all viewers right away
796 obj.sendToAllViewers(data);
797 break;
798 + case 18: // MNG_KVM_KEYSTATE
799 + // Store and send this to all viewers right away
800 + obj.lastKeyState = data;
801 + obj.sendToAllInputViewers(data);
802 + break;
803 case 65: // Alert
804 // Send this to all viewers right away
805 obj.sendToAllViewers(data);
public/scripts/agent-desktop-0.0.2.js
+16 -10
@@ -263,17 +263,17 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
263 case 15: // KVM_TOUCH
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;
266 case 17: // MNG_KVM_MESSAGE
267 var str = String.fromCharCode.apply(null, view.slice(4));
268 console.log('Got KVM Message: ' + str);
269 if (obj.onMessage != null) obj.onMessage(str, obj);
270 break;
271 + case 18: // MNG_KVM_KEYSTATE
272 + if ((cmdsize != 5) || (obj.KeyboardState == view[4])) break;
273 + obj.KeyboardState = view[4]; // 1 = NumLock, 2 = ScrollLock, 4 = CapsLock
274 + if (obj.onKeyboardStateChanged) { obj.onKeyboardStateChanged(obj, obj.KeyboardState); }
275 + console.log('MNG_KVM_KEYSTATE:' + ((obj.KeyboardState & 1) ? ' NumLock' : '') + ((obj.KeyboardState & 2) ? ' ScrollLock' : '') + ((obj.KeyboardState & 4) ? ' CapsLock' : ''));
276 + break;
277 case 65: // Alert
278 var str = String.fromCharCode.apply(null, view.slice(4));
279 if (str[0] != '.') {
@@ -401,7 +401,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
401 if (action == null) return;
402 if (!event) { event = window.event; }
403
404 - var extendedKey = false;
404 + var extendedKey = false; // Test feature, add ?extkeys=1 to url to use.
405 if ((typeof event.code == 'string') && (event.code.startsWith('Arrow') || (extendedKeyTable.indexOf(event.code) >= 0))) { extendedKey = true; }
406
407 if ((extendedKey == false) && event.code && (event.code.startsWith('NumPad') == false) && (obj.localKeyMap == false)) {
@@ -580,13 +580,17 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
580 obj.xxMouseWheel = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
581 obj.xxKeyUp = function (e) {
582 if ((e.key != 'Dead') && (obj.State == 3)) {
583 - if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)) && (e.key.charCodeAt(0) < 42) && (e.key.charCodeAt(0) > 47)) { obj.SendKeyUnicode(obj.KeyAction.UP, e.key.charCodeAt(0)); } else { obj.SendKeyMsg(obj.KeyAction.UP, e); }
583 + if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0))) {
584 + obj.SendKeyUnicode(obj.KeyAction.UP, e.key.charCodeAt(0));
585 + } else {
586 + obj.SendKeyMsg(obj.KeyAction.UP, e);
587 + }
588 }
589 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
590 }
591 obj.xxKeyDown = function (e) {
592 if ((e.key != 'Dead') && (obj.State == 3)) {
589 - if (!((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)) && (e.key.charCodeAt(0) < 42) && (e.key.charCodeAt(0) > 47))) {
593 + if (!((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)))) {
594 obj.SendKeyMsg(obj.KeyAction.DOWN, e);
595 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
596 }
@@ -594,7 +598,9 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
598 }
599 obj.xxKeyPress = function (e) {
600 if ((e.key != 'Dead') && (obj.State == 3)) {
597 - if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)) && (e.key.charCodeAt(0) < 42) && (e.key.charCodeAt(0) > 47)) { obj.SendKeyUnicode(obj.KeyAction.DOWN, e.key.charCodeAt(0)); } //else { obj.SendKeyMsg(obj.KeyAction.DOWN, e); }
601 + if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0))) {
602 + obj.SendKeyUnicode(obj.KeyAction.DOWN, e.key.charCodeAt(0));
603 + } // else { obj.SendKeyMsg(obj.KeyAction.DOWN, e); }
604 }
605 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
606 }
views/default.handlebars
+53 -25
@@ -612,6 +612,17 @@
612 <div class="icon2"></div>
613 <div class="warningbox">Remote computer is not powered on, click here to issue a power command.</div>
614 </div>
615 + <div style="position:absolute;right:16px;margin-top:-14px;font-size:x-small;color:black">
616 + <div id="p11capslock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
617 + CAPS
618 + </div>
619 + <div id="p11scrolllock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
620 + SCROLL
621 + </div>
622 + <div id="p11numlock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
623 + NUM
624 + </div>
625 + </div>
626 <div id=deskarea0 cellpadding=0 cellspacing=0>
627 <div id=deskarea1 class="areaHead">
628 <div class="toright2">
@@ -3733,7 +3744,7 @@
3744
3745 function ondockeypress(e) {
3746 setSessionActivity();
3736 - if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
3747 + if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
3748 // Check what keys we are allows to send
3749 if (currentNode != null) {
3750 var meshrights = GetNodeRights(currentNode);
@@ -3744,14 +3755,14 @@
3755 }
3756 return desktop.m.handleKeys(e);
3757 }
3747 - if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { return terminal.m.TermHandleKeys(e); }
3758 + if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && (xterm == null)) { return terminal.m.TermHandleKeys(e); }
3759 if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) return agentConsoleHandleKeys(e);
3760 if (!xxdialogMode && xxcurrentView == 4) {
3750 - if (e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
3761 + if ((e.ctrlKey == true) || (e.altKey == true) || (e.metaKey == true)) return;
3762 var processed = 0;
3763 if (e.key) {
3753 - if (e.key.length === 1 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + e.key)); processed = 1; }
3754 - if (e.keyCode == 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = x.substring(0, x.length - 1); processed = 1; }
3764 + if ((e.key.length === 1) && (userSearchFocus == 0)) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + e.key)); processed = 1; }
3765 + if ((e.keyCode == 8) && (userSearchFocus == 0)) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = x.substring(0, x.length - 1); processed = 1; }
3766 if (e.keyCode == 27) { Q('UserSearchInput').value = ''; processed = 1; }
3767 } else {
3768 if (e.charCode != 0 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + String.fromCharCode(e.charCode))); processed = 1; }
@@ -3770,8 +3781,8 @@
3781 if (Q('viewselect').value < 4) {
3782 var processed = 0;
3783 if (e.key) {
3773 - if (e.key.length === 1 && searchFocus == 0) { Q('KvmSearchInput').value = Q('SearchInput').value = ((Q('SearchInput').value + e.key)); processed = 1; }
3774 - if (e.keyCode == 8 && searchFocus == 0) { var x = Q('SearchInput').value; Q('KvmSearchInput').value = Q('SearchInput').value = x.substring(0, x.length - 1); processed = 1; }
3784 + if ((e.key.length === 1) && (searchFocus == 0)) { Q('KvmSearchInput').value = Q('SearchInput').value = ((Q('SearchInput').value + e.key)); processed = 1; }
3785 + if ((e.keyCode == 8) && (searchFocus == 0)) { var x = Q('SearchInput').value; Q('KvmSearchInput').value = Q('SearchInput').value = x.substring(0, x.length - 1); processed = 1; }
3786 if (e.keyCode == 27) { Q('KvmSearchInput').value = Q('SearchInput').value = ''; processed = 1; }
3787 } else {
3788 if (e.charCode != 0 && searchFocus == 0) { Q('KvmSearchInput').value = Q('SearchInput').value = ((Q('SearchInput').value + String.fromCharCode(e.charCode))); processed = 1; }
@@ -3780,7 +3791,7 @@
3791 }
3792 if (Q('viewselect').value == 4) {
3793 if (e.key) {
3783 - if (e.key.length === 1 && mapSearchFocus == 0) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + e.key)); processed = 1; }
3794 + if ((e.key.length === 1) && (mapSearchFocus == 0)) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + e.key)); processed = 1; }
3795 //if (e.keyCode == 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = x.substring(0, x.length - 1); processed = 1; }
3796 if (e.keyCode == 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
3797 if (e.keyCode == 13) { getSearchLocation(); }
@@ -3792,7 +3803,7 @@
3803
3804 function ondockeydown(e) {
3805 setSessionActivity();
3795 - if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
3806 + if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
3807 // Check what keys we are allows to send
3808 if (currentNode != null) {
3809 var meshrights = GetNodeRights(currentNode);
@@ -3803,30 +3814,30 @@
3814 }
3815 return desktop.m.handleKeyDown(e);
3816 }
3806 - if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { terminal.m.TermHandleKeyDown(e); if ((e.keyCode >= 37) && (e.keyCode <= 40)) { haltEvent(e); } }
3807 - if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { haltEvent(e); return false; } // F5 Refresh on files
3817 + if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && xterm == null) { terminal.m.TermHandleKeyDown(e); if ((e.keyCode >= 37) && (e.keyCode <= 40)) { haltEvent(e); } }
3818 + if (!xxdialogMode && (xxcurrentView == 13) && (e.keyCode == 116) && (p13filetree != null)) { haltEvent(e); return false; } // F5 Refresh on files
3819 if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) { return agentConsoleHandleKeys(e); }
3809 - if (!xxdialogMode && xxcurrentView == 4) {
3810 - if (e.keyCode === 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
3820 + if (!xxdialogMode && (xxcurrentView == 4)) {
3821 + if ((e.keyCode === 8) && (userSearchFocus == 0)) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
3822 if (e.keyCode === 27) { Q('UserSearchInput').value = ''; processed = 1; }
3823 if (processed > 0) { if (processed == 1) { mainUpdate(5); } return haltEvent(e); }
3824 }
3814 - if (xxdialogMode || xxcurrentView != 1 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
3825 + if (xxdialogMode || (xxcurrentView != 1) || (e.ctrlKey == true) || (e.altKey == true) || (e.metaKey == true)) return;
3826 var processed = 0;
3827 if (Q('viewselect').value < 4) {
3817 - if (e.keyCode === 8 && searchFocus == 0) { var x = Q('SearchInput').value; Q('KvmSearchInput').value = Q('SearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
3828 + if ((e.keyCode === 8) && (searchFocus == 0)) { var x = Q('SearchInput').value; Q('KvmSearchInput').value = Q('SearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
3829 if (e.keyCode === 27) { Q('KvmSearchInput').value = Q('SearchInput').value = ''; processed = 1; }
3830 if (processed > 0) { if (processed == 1) { mainUpdate(5); } return haltEvent(e); }
3831 }
3832 if (Q('viewselect').value == 4) {
3822 - if (e.keyCode === 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = (x.substring(0, x.length - 1)); processed = 1; }
3833 + if ((e.keyCode === 8) && (mapSearchFocus == 0)) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = (x.substring(0, x.length - 1)); processed = 1; }
3834 if (e.keyCode === 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
3835 }
3836 }
3837
3838 function ondockeyup(e) {
3839 setSessionActivity();
3829 - if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
3840 + if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
3841 // Check what keys we are allows to send
3842 if (currentNode != null) {
3843 var meshrights = GetNodeRights(currentNode);
@@ -3837,14 +3848,14 @@
3848 }
3849 return desktop.m.handleKeyUp(e);
3850 }
3840 - if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { return terminal.m.TermHandleKeyUp(e); }
3841 - if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { p13folderup(9999); haltEvent(e); return false; } // F5 Refresh on files
3842 - if (!xxdialogMode && xxcurrentView == 4) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
3843 - if (xxdialogMode && e.keyCode == 27) { dialogclose(0); }
3851 + if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && xterm == null) { return terminal.m.TermHandleKeyUp(e); }
3852 + if (!xxdialogMode && (xxcurrentView == 13) && (e.keyCode == 116) && (p13filetree != null)) { p13folderup(9999); haltEvent(e); return false; } // F5 Refresh on files
3853 + if (!xxdialogMode && (xxcurrentView == 4)) { if (((e.keyCode === 8) && (searchFocus == 0)) || e.keyCode === 27) { return haltEvent(e); } }
3854 + if (xxdialogMode && (e.keyCode == 27)) { dialogclose(0); }
3855 if ((e.shiftKey == true) && (e.keyCode == 27)) { dialogclose(0); Q('KvmSearchInput').value = Q('SearchInput').value = ''; mainUpdate(5); if (desktop != null) { connectDesktop(); } if (terminal != null) { connectTerminal(); } if (files != null) { connectFiles(); } go(1); return; } // Shift-ESC: Reset the web page
3845 - if (xxdialogMode || xxcurrentView != 0 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
3846 - if (Q('viewselect').value < 4) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
3847 - if (Q('viewselect').value == 4) { if ((e.keyCode === 8 && mapSearchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
3856 + if (xxdialogMode || xxcurrentView != 0 || e.ctrlKey == true || (e.altKey == true) || (e.metaKey == true)) return;
3857 + if (Q('viewselect').value < 4) { if (((e.keyCode === 8) && (searchFocus == 0)) || (e.keyCode === 27)) { return haltEvent(e); } }
3858 + if (Q('viewselect').value == 4) { if (((e.keyCode === 8) && (mapSearchFocus == 0)) || (e.keyCode === 27)) { return haltEvent(e); } }
3859 }
3860
3861 //function ondocfocus() { }
@@ -4237,6 +4248,7 @@
4248 desktop.shortid = shortid;
4249 desktop.onStateChanged = onMultiDesktopStateChange;
4250 desktop.m.onRemoteInputLockChanged = null;
4251 + desktop.m.onKeyboardStateChanged = null;
4252 multiDesktop[id] = desktop;
4253 desktop = desktopNode = currentNode = null;
4254 // Setup a replacement desktop
@@ -8174,6 +8186,11 @@
8186 QV('DeskInputLockedButton', desktop.m.RemoteInputLock === 1);
8187 QV('DeskInputUnLockedButton', desktop.m.RemoteInputLock === 0);
8188 desktop.m.onRemoteInputLockChanged = function(obj, state) { QV('DeskInputLockedButton', state); QV('DeskInputUnLockedButton', !state); }
8189 + desktop.m.onKeyboardStateChanged = function(obj, state) {
8190 + QS('p11numlock').display = ((state & 1) ? 'inline-block' : 'none');
8191 + QS('p11scrolllock').display = ((state & 2) ? 'inline-block' : 'none');
8192 + QS('p11capslock').display = ((state & 4) ? 'inline-block' : 'none');
8193 + }
8194 desktopNode = currentNode;
8195 onDesktopStateChange(desktop, desktop.State);
8196 delete multiDesktop[currentNode._id];
@@ -8252,7 +8269,13 @@
8269 QV('d7deskAutoClipboardLabel', (navigator.clipboard.readText != null) && ((features2 & 0x1000) == 0));
8270 QV('DeskClipboardInButton', online && inputAllowed && ((features2 & 0x0800) == 0) && (navigator.clipboard != null) && (navigator.clipboard.writeText != null) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
8271
8255 - if (deskState != 3) { QV('DeskInputLockedButton', false); QV('DeskInputUnLockedButton', false); }
8272 + if (deskState != 3) {
8273 + QV('DeskInputLockedButton', false);
8274 + QV('DeskInputUnLockedButton', false);
8275 + QV('p11numlock', false);
8276 + QV('p11scrolllock', false);
8277 + QV('p11capslock', false);
8278 + }
8279
8280 // Display this only if we have Chat & Notify permissions
8281 QV('DeskSaveImageButton', (deskState == 3) && (Q('Desk')['toBlob'] != null) && ((features2 & 0x400) == 0));
@@ -8393,6 +8416,11 @@
8416 desktop.onStateChanged = onDesktopStateChange;
8417 if ((features2 & 0x2000) != 0) desktop.m.stopInput = true;
8418 desktop.m.onRemoteInputLockChanged = function(obj, state) { QV('DeskInputLockedButton', state); QV('DeskInputUnLockedButton', !state); }
8419 + desktop.m.onKeyboardStateChanged = function(obj, state) {
8420 + QS('p11numlock').display = ((state & 1) ? 'inline-block' : 'none');
8421 + QS('p11scrolllock').display = ((state & 2) ? 'inline-block' : 'none');
8422 + QS('p11capslock').display = ((state & 4) ? 'inline-block' : 'none');
8423 + }
8424 desktop.onConsoleMessageChange = function () {
8425 if (desktop.consoleMessage) {
8426 Q('p11DeskConsoleMsg').innerHTML += formatAgentConsoleMessage(desktop.consoleMessage, desktop.consoleMessageId, desktop.consoleMessageArgs);