Fixed keyboard mapping for remote desktop (software and hardware KVM)

This commit is contained in:
Ylian Saint-Hilaire 2019-01-06 20:23:29 -08:00
parent 95d00c20a7
commit c21821312a
6 changed files with 214 additions and 50 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.2.5-u", "version": "0.2.5-v",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -259,15 +259,102 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.InputType = { "KEY": 1, "MOUSE": 2, "CTRLALTDEL": 10, "TOUCH": 15 }; obj.InputType = { "KEY": 1, "MOUSE": 2, "CTRLALTDEL": 10, "TOUCH": 15 };
obj.Alternate = 0; obj.Alternate = 0;
var convertKeyCodeTable = {
"Pause": 19,
"CapsLock": 20,
"Space": 32,
"Quote": 222,
"Minus": 189,
"NumpadMultiply": 106,
"NumpadAdd": 107,
"PrintScreen": 44,
"Comma": 188,
"NumpadSubtract": 109,
"NumpadDecimal": 110,
"Period": 190,
"Slash": 191,
"NumpadDivide": 111,
"Semicolon": 186,
"Equal": 187,
"OSLeft": 91,
"BracketLeft": 219,
"OSRight": 91,
"Backslash": 220,
"BracketRight": 221,
"ContextMenu": 93,
"Backquote": 192,
"NumLock": 144,
"ScrollLock": 145,
"Backspace": 8,
"Tab": 9,
"Enter": 13,
"NumpadEnter": 13,
"Escape": 27,
"Delete": 46,
"Home": 36,
"PageUp": 33,
"PageDown": 34,
"ArrowLeft": 37,
"ArrowUp": 38,
"ArrowRight": 39,
"ArrowDown": 40,
"End": 35,
"Insert": 45,
"F1": 112,
"F2": 113,
"F3": 114,
"F4": 115,
"F5": 116,
"F6": 117,
"F7": 118,
"F8": 119,
"F9": 120,
"F10": 121,
"F11": 122,
"F12": 123,
"ShiftLeft": 16,
"ShiftRight": 16,
"ControlLeft": 17,
"ControlRight": 17,
"AltLeft": 18,
"AltRight": 18,
"MetaLeft": 91,
"MetaRight": 92,
"VolumeMute": 181
//"LaunchMail":
//"LaunchApp1":
//"LaunchApp2":
//"BrowserStop":
//"MediaStop":
//"MediaTrackPrevious":
//"MediaTrackNext":
//"MediaPlayPause":
//"MediaSelect":
}
function convertKeyCode(e) {
if (e.code.startsWith('Key') && e.code.length == 4) { return e.code.charCodeAt(3); }
if (e.code.startsWith('Digit') && e.code.length == 6) { return e.code.charCodeAt(5); }
if (e.code.startsWith('Numpad') && e.code.length == 7) { return e.code.charCodeAt(6) + 48; }
return convertKeyCodeTable[e.code];
}
obj.SendKeyMsg = function (action, event) { obj.SendKeyMsg = function (action, event) {
if (action == null) return; if (action == null) return;
if (!event) { var event = window.event; } if (!event) { event = window.event; }
if (event.code) {
// Convert "event.code" into a scancode. This works the same regardless of the keyboard language.
// Older browsers will not support this.
var kc = convertKeyCode(event);
if (kc != null) { obj.SendKeyMsgKC(action, kc); }
} else {
// Use this keycode, this works best with "US-EN" keyboards.
// Older browser support this.
var kc = event.keyCode; var kc = event.keyCode;
if (kc == 59) kc = 186; // Correct for ';' key in Firefox if (kc == 0x3B) { kc = 0xBA; } // Fix the ';' key
if (kc == 61) kc = 187; // Correct for '=' key in Firefox
if (kc == 173) kc = 189; // Correct for '-' key in Firefox
obj.SendKeyMsgKC(action, kc); obj.SendKeyMsgKC(action, kc);
} }
}
obj.SendMessage = function (msg) { obj.SendMessage = function (msg) {
if (obj.State == 3) obj.send(String.fromCharCode(0x00, 0x11) + obj.shortToStr(4 + msg.length) + msg); // 0x11 = 17 MNG_KVM_MESSAGE if (obj.State == 3) obj.send(String.fromCharCode(0x00, 0x11) + obj.shortToStr(4 + msg.length) + msg); // 0x11 = 17 MNG_KVM_MESSAGE

View File

@ -548,6 +548,75 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
obj.parent.send(x); obj.parent.send(x);
} }
var convertAmtKeyCodeTable = {
"Pause": 19,
"CapsLock": 20,
"Space": 32,
"Quote": 39,
"Minus": 45,
"NumpadMultiply": 42,
"NumpadAdd": 43,
"PrintScreen": 44,
"Comma": 44,
"NumpadSubtract": 45,
"NumpadDecimal": 46,
"Period": 46,
"Slash": 47,
"NumpadDivide": 47,
"Semicolon": 59,
"Equal": 61,
"OSLeft": 91,
"BracketLeft": 91,
"OSRight": 91,
"Backslash": 92,
"BracketRight": 93,
"ContextMenu": 93,
"Backquote": 96,
"NumLock": 144,
"ScrollLock": 145,
"Backspace": 0xff08,
"Tab": 0xff09,
"Enter": 0xff0d,
"NumpadEnter": 0xff0d,
"Escape": 0xff1b,
"Delete": 0xffff,
"Home": 0xff50,
"PageUp": 0xff55,
"PageDown": 0xff56,
"ArrowLeft": 0xff51,
"ArrowUp": 0xff52,
"ArrowRight": 0xff53,
"ArrowDown": 0xff54,
"End": 0xff57,
"Insert": 0xff63,
"F1": 0xffbe,
"F2": 0xffbf,
"F3": 0xffc0,
"F4": 0xffc1,
"F5": 0xffc2,
"F6": 0xffc3,
"F7": 0xffc4,
"F8": 0xffc5,
"F9": 0xffc6,
"F10": 0xffc7,
"F11": 0xffc8,
"F12": 0xffc9,
"ShiftLeft": 0xffe1,
"ShiftRight": 0xffe2,
"ControlLeft": 0xffe3,
"ControlRight": 0xffe4,
"AltLeft": 0xffe9,
"AltRight": 0xffea,
"MetaLeft": 0xffe7,
"MetaRight": 0xffe8
}
function convertAmtKeyCode(e) {
if (e.code.startsWith('Key') && e.code.length == 4) { return e.code.charCodeAt(3) + ((e.shiftKey == false) ? 32 : 0); }
if (e.code.startsWith('Digit') && e.code.length == 6) { return e.code.charCodeAt(5); }
if (e.code.startsWith('Numpad') && e.code.length == 7) { return e.code.charCodeAt(6); }
return convertAmtKeyCodeTable[e.code];
}
/* /*
Intel AMT only recognizes a small subset of keysym characters defined in the keysymdef.h so you dont need to Intel AMT only recognizes a small subset of keysym characters defined in the keysymdef.h so you dont need to
implement all the languages (this is taken care by the USB Scancode Extension in RFB4.0 protocol). implement all the languages (this is taken care by the USB Scancode Extension in RFB4.0 protocol).
@ -564,6 +633,13 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
function _keyevent(d, e) { function _keyevent(d, e) {
if (!e) { e = window.event; } if (!e) { e = window.event; }
if (e.code) {
// For new browsers, this mapping is keyboard language independent
var k = convertAmtKeyCode(e);
if (k != null) { obj.sendkey(k, d); }
} else {
// For older browsers, this mapping works best for EN-US keyboard
var k = e.keyCode, kk = k; var k = e.keyCode, kk = k;
if (e.shiftKey == false && k >= 65 && k <= 90) kk = k + 32; if (e.shiftKey == false && k >= 65 && k <= 90) kk = k + 32;
if (k >= 112 && k <= 124) kk = k + 0xFF4E; if (k >= 112 && k <= 124) kk = k + 0xFF4E;
@ -603,6 +679,7 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
if (k == 222) kk = 39; // ' if (k == 222) kk = 39; // '
//console.log('Key' + d + ": " + k + " = " + kk); //console.log('Key' + d + ": " + k + " = " + kk);
obj.sendkey(kk, d); obj.sendkey(kk, d);
}
return obj.haltEvent(e); return obj.haltEvent(e);
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1555,7 +1555,7 @@
break; break;
} }
default: default:
console.log('Unknown message.event.action', message.event.action); //console.log('Unknown message.event.action', message.event.action);
break; break;
} }
break; break;
@ -3894,7 +3894,7 @@
case 2: case 2:
break; break;
default: default:
console.log('Unknown onDesktopStateChange state', state); //console.log('Unknown onDesktopStateChange state', state);
break; break;
} }
updateDesktopButtons(); updateDesktopButtons();