Keyboard mapping fix.

This commit is contained in:
Ylian Saint-Hilaire 2022-02-28 12:32:07 -08:00
parent bdb12ce7cc
commit 22bf06837d
3 changed files with 76 additions and 41 deletions

View File

@ -34,8 +34,9 @@ MNG_KVM_SET_DISPLAY = 12,
MNG_KVM_FRAME_RATE_TIMER = 13,
MNG_KVM_INIT_TOUCH = 14,
MNG_KVM_TOUCH = 15,
MNG_KVM_KEYSTATE = 16,
MNG_KVM_CONNECTCOUNT = 16,
MNG_KVM_MESSAGE = 17,
MNG_KVM_KEYSTATE = 18,
MNG_ECHO = 21,
MNG_JUMBO = 27,
MNG_GETDIR = 50,
@ -790,15 +791,15 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, id, func) {
break;
case 15: // KVM_TOUCH
break;
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
obj.sendToAllViewers(data);
break;
case 18: // MNG_KVM_KEYSTATE
// Store and send this to all viewers right away
obj.lastKeyState = data;
obj.sendToAllInputViewers(data);
break;
case 65: // Alert
// Send this to all viewers right away
obj.sendToAllViewers(data);

View File

@ -263,17 +263,17 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
case 15: // KVM_TOUCH
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));
console.log('Got KVM Message: ' + str);
if (obj.onMessage != null) obj.onMessage(str, obj);
break;
case 18: // 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 65: // Alert
var str = String.fromCharCode.apply(null, view.slice(4));
if (str[0] != '.') {
@ -401,7 +401,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
if (action == null) return;
if (!event) { event = window.event; }
var extendedKey = false;
var extendedKey = false; // Test feature, add ?extkeys=1 to url to use.
if ((typeof event.code == 'string') && (event.code.startsWith('Arrow') || (extendedKeyTable.indexOf(event.code) >= 0))) { extendedKey = true; }
if ((extendedKey == false) && event.code && (event.code.startsWith('NumPad') == false) && (obj.localKeyMap == false)) {
@ -580,13 +580,17 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.xxMouseWheel = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
obj.xxKeyUp = function (e) {
if ((e.key != 'Dead') && (obj.State == 3)) {
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); }
if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0))) {
obj.SendKeyUnicode(obj.KeyAction.UP, e.key.charCodeAt(0));
} else {
obj.SendKeyMsg(obj.KeyAction.UP, e);
}
}
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}
obj.xxKeyDown = function (e) {
if ((e.key != 'Dead') && (obj.State == 3)) {
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))) {
if (!((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)))) {
obj.SendKeyMsg(obj.KeyAction.DOWN, e);
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}
@ -594,7 +598,9 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
}
obj.xxKeyPress = function (e) {
if ((e.key != 'Dead') && (obj.State == 3)) {
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); }
if ((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0))) {
obj.SendKeyUnicode(obj.KeyAction.DOWN, e.key.charCodeAt(0));
} // else { obj.SendKeyMsg(obj.KeyAction.DOWN, e); }
}
if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
}

View File

@ -612,6 +612,17 @@
<div class="icon2"></div>
<div class="warningbox">Remote computer is not powered on, click here to issue a power command.</div>
</div>
<div style="position:absolute;right:16px;margin-top:-14px;font-size:x-small;color:black">
<div id="p11capslock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
CAPS
</div>
<div id="p11scrolllock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
SCROLL
</div>
<div id="p11numlock" style="display:none;margin-left:1px;border-radius:5px;background-color:lightgreen;padding:2px">
NUM
</div>
</div>
<div id=deskarea0 cellpadding=0 cellspacing=0>
<div id=deskarea1 class="areaHead">
<div class="toright2">
@ -3733,7 +3744,7 @@
function ondockeypress(e) {
setSessionActivity();
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
// Check what keys we are allows to send
if (currentNode != null) {
var meshrights = GetNodeRights(currentNode);
@ -3744,14 +3755,14 @@
}
return desktop.m.handleKeys(e);
}
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { return terminal.m.TermHandleKeys(e); }
if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && (xterm == null)) { return terminal.m.TermHandleKeys(e); }
if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) return agentConsoleHandleKeys(e);
if (!xxdialogMode && xxcurrentView == 4) {
if (e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
if ((e.ctrlKey == true) || (e.altKey == true) || (e.metaKey == true)) return;
var processed = 0;
if (e.key) {
if (e.key.length === 1 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + e.key)); processed = 1; }
if (e.keyCode == 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = x.substring(0, x.length - 1); processed = 1; }
if ((e.key.length === 1) && (userSearchFocus == 0)) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + e.key)); processed = 1; }
if ((e.keyCode == 8) && (userSearchFocus == 0)) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = x.substring(0, x.length - 1); processed = 1; }
if (e.keyCode == 27) { Q('UserSearchInput').value = ''; processed = 1; }
} else {
if (e.charCode != 0 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + String.fromCharCode(e.charCode))); processed = 1; }
@ -3770,8 +3781,8 @@
if (Q('viewselect').value < 4) {
var processed = 0;
if (e.key) {
if (e.key.length === 1 && searchFocus == 0) { Q('KvmSearchInput').value = Q('SearchInput').value = ((Q('SearchInput').value + e.key)); processed = 1; }
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; }
if ((e.key.length === 1) && (searchFocus == 0)) { Q('KvmSearchInput').value = Q('SearchInput').value = ((Q('SearchInput').value + e.key)); processed = 1; }
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; }
if (e.keyCode == 27) { Q('KvmSearchInput').value = Q('SearchInput').value = ''; processed = 1; }
} else {
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 @@
}
if (Q('viewselect').value == 4) {
if (e.key) {
if (e.key.length === 1 && mapSearchFocus == 0) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + e.key)); processed = 1; }
if ((e.key.length === 1) && (mapSearchFocus == 0)) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + e.key)); processed = 1; }
//if (e.keyCode == 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = x.substring(0, x.length - 1); processed = 1; }
if (e.keyCode == 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
if (e.keyCode == 13) { getSearchLocation(); }
@ -3792,7 +3803,7 @@
function ondockeydown(e) {
setSessionActivity();
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
// Check what keys we are allows to send
if (currentNode != null) {
var meshrights = GetNodeRights(currentNode);
@ -3803,30 +3814,30 @@
}
return desktop.m.handleKeyDown(e);
}
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { terminal.m.TermHandleKeyDown(e); if ((e.keyCode >= 37) && (e.keyCode <= 40)) { haltEvent(e); } }
if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { haltEvent(e); return false; } // F5 Refresh on files
if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && xterm == null) { terminal.m.TermHandleKeyDown(e); if ((e.keyCode >= 37) && (e.keyCode <= 40)) { haltEvent(e); } }
if (!xxdialogMode && (xxcurrentView == 13) && (e.keyCode == 116) && (p13filetree != null)) { haltEvent(e); return false; } // F5 Refresh on files
if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) { return agentConsoleHandleKeys(e); }
if (!xxdialogMode && xxcurrentView == 4) {
if (e.keyCode === 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
if (!xxdialogMode && (xxcurrentView == 4)) {
if ((e.keyCode === 8) && (userSearchFocus == 0)) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
if (e.keyCode === 27) { Q('UserSearchInput').value = ''; processed = 1; }
if (processed > 0) { if (processed == 1) { mainUpdate(5); } return haltEvent(e); }
}
if (xxdialogMode || xxcurrentView != 1 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
if (xxdialogMode || (xxcurrentView != 1) || (e.ctrlKey == true) || (e.altKey == true) || (e.metaKey == true)) return;
var processed = 0;
if (Q('viewselect').value < 4) {
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; }
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; }
if (e.keyCode === 27) { Q('KvmSearchInput').value = Q('SearchInput').value = ''; processed = 1; }
if (processed > 0) { if (processed == 1) { mainUpdate(5); } return haltEvent(e); }
}
if (Q('viewselect').value == 4) {
if (e.keyCode === 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = (x.substring(0, x.length - 1)); processed = 1; }
if ((e.keyCode === 8) && (mapSearchFocus == 0)) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = (x.substring(0, x.length - 1)); processed = 1; }
if (e.keyCode === 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
}
}
function ondockeyup(e) {
setSessionActivity();
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q('DeskControl').checked) {
if (!xxdialogMode && (xxcurrentView == 11) && desktop && Q('DeskControl').checked) {
// Check what keys we are allows to send
if (currentNode != null) {
var meshrights = GetNodeRights(currentNode);
@ -3837,14 +3848,14 @@
}
return desktop.m.handleKeyUp(e);
}
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3 && xterm == null) { return terminal.m.TermHandleKeyUp(e); }
if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { p13folderup(9999); haltEvent(e); return false; } // F5 Refresh on files
if (!xxdialogMode && xxcurrentView == 4) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
if (xxdialogMode && e.keyCode == 27) { dialogclose(0); }
if (!xxdialogMode && (xxcurrentView == 12) && terminal && (terminal.State == 3) && xterm == null) { return terminal.m.TermHandleKeyUp(e); }
if (!xxdialogMode && (xxcurrentView == 13) && (e.keyCode == 116) && (p13filetree != null)) { p13folderup(9999); haltEvent(e); return false; } // F5 Refresh on files
if (!xxdialogMode && (xxcurrentView == 4)) { if (((e.keyCode === 8) && (searchFocus == 0)) || e.keyCode === 27) { return haltEvent(e); } }
if (xxdialogMode && (e.keyCode == 27)) { dialogclose(0); }
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
if (xxdialogMode || xxcurrentView != 0 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
if (Q('viewselect').value < 4) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
if (Q('viewselect').value == 4) { if ((e.keyCode === 8 && mapSearchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
if (xxdialogMode || xxcurrentView != 0 || e.ctrlKey == true || (e.altKey == true) || (e.metaKey == true)) return;
if (Q('viewselect').value < 4) { if (((e.keyCode === 8) && (searchFocus == 0)) || (e.keyCode === 27)) { return haltEvent(e); } }
if (Q('viewselect').value == 4) { if (((e.keyCode === 8) && (mapSearchFocus == 0)) || (e.keyCode === 27)) { return haltEvent(e); } }
}
//function ondocfocus() { }
@ -4237,6 +4248,7 @@
desktop.shortid = shortid;
desktop.onStateChanged = onMultiDesktopStateChange;
desktop.m.onRemoteInputLockChanged = null;
desktop.m.onKeyboardStateChanged = null;
multiDesktop[id] = desktop;
desktop = desktopNode = currentNode = null;
// Setup a replacement desktop
@ -8174,6 +8186,11 @@
QV('DeskInputLockedButton', desktop.m.RemoteInputLock === 1);
QV('DeskInputUnLockedButton', desktop.m.RemoteInputLock === 0);
desktop.m.onRemoteInputLockChanged = function(obj, state) { QV('DeskInputLockedButton', state); QV('DeskInputUnLockedButton', !state); }
desktop.m.onKeyboardStateChanged = function(obj, state) {
QS('p11numlock').display = ((state & 1) ? 'inline-block' : 'none');
QS('p11scrolllock').display = ((state & 2) ? 'inline-block' : 'none');
QS('p11capslock').display = ((state & 4) ? 'inline-block' : 'none');
}
desktopNode = currentNode;
onDesktopStateChange(desktop, desktop.State);
delete multiDesktop[currentNode._id];
@ -8252,7 +8269,13 @@
QV('d7deskAutoClipboardLabel', (navigator.clipboard.readText != null) && ((features2 & 0x1000) == 0));
QV('DeskClipboardInButton', online && inputAllowed && ((features2 & 0x0800) == 0) && (navigator.clipboard != null) && (navigator.clipboard.writeText != null) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null)));
if (deskState != 3) { QV('DeskInputLockedButton', false); QV('DeskInputUnLockedButton', false); }
if (deskState != 3) {
QV('DeskInputLockedButton', false);
QV('DeskInputUnLockedButton', false);
QV('p11numlock', false);
QV('p11scrolllock', false);
QV('p11capslock', false);
}
// Display this only if we have Chat & Notify permissions
QV('DeskSaveImageButton', (deskState == 3) && (Q('Desk')['toBlob'] != null) && ((features2 & 0x400) == 0));
@ -8393,6 +8416,11 @@
desktop.onStateChanged = onDesktopStateChange;
if ((features2 & 0x2000) != 0) desktop.m.stopInput = true;
desktop.m.onRemoteInputLockChanged = function(obj, state) { QV('DeskInputLockedButton', state); QV('DeskInputUnLockedButton', !state); }
desktop.m.onKeyboardStateChanged = function(obj, state) {
QS('p11numlock').display = ((state & 1) ? 'inline-block' : 'none');
QS('p11scrolllock').display = ((state & 2) ? 'inline-block' : 'none');
QS('p11capslock').display = ((state & 4) ? 'inline-block' : 'none');
}
desktop.onConsoleMessageChange = function () {
if (desktop.consoleMessage) {
Q('p11DeskConsoleMsg').innerHTML += formatAgentConsoleMessage(desktop.consoleMessage, desktop.consoleMessageId, desktop.consoleMessageArgs);