Fixed remote desktop key mappings.

Ylian Saint-Hilaire committed Feb 23, 2022 at 14:07 UTC 1e2fba445846efa187cb2468f1779a92fc9efcdf
1 file changed +17 -10
public/scripts/agent-desktop-0.0.2.js
+17 -10
@@ -386,14 +386,19 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
386 return convertKeyCodeTable[e.code];
387 }
388
389 + var extendedKeyTable = ['ShiftRight', 'AltRight', 'ControlRight', 'Home', 'End', 'Insert', 'Delete', 'PageUp', 'PageDown', 'NumpadDivide', 'NumpadEnter', 'NumLock', 'Pause'];
390 obj.SendKeyMsg = function (action, event) {
391 if (action == null) return;
392 if (!event) { event = window.event; }
392 - if (event.code && (obj.localKeyMap == false)) {
393 +
394 + var extendedKey = false;
395 + if ((typeof event.code == 'string') && (event.code.startsWith('Arrow') || (extendedKeyTable.indexOf(event.code) >= 0))) { extendedKey = true; }
396 +
397 + if ((extendedKey == false) && event.code && (event.code.startsWith('NumPad') == false) && (obj.localKeyMap == false)) {
398 // Convert "event.code" into a scancode. This works the same regardless of the keyboard language.
399 // Older browsers will not support this.
400 var kc = convertKeyCode(event);
396 - if (kc != null) { obj.SendKeyMsgKC(action, kc); }
401 + if (kc != null) { obj.SendKeyMsgKC(action, kc, extendedKey); }
402 } else {
403 // Use this keycode, this works best with "US-EN" keyboards.
404 // Older browser support this.
@@ -401,7 +406,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
406 if (kc == 0x3B) { kc = 0xBA; } // Fix the ';' key
407 else if (kc == 173) { kc = 189; } // Fix the '-' key for Firefox
408 else if (kc == 61) { kc = 187; } // Fix the '=' key for Firefox
404 - obj.SendKeyMsgKC(action, kc);
409 + obj.SendKeyMsgKC(action, kc, extendedKey);
410 }
411 }
412
@@ -412,9 +417,9 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
417 if (obj.State == 3) obj.send(String.fromCharCode(0x00, 0x11) + obj.shortToStr(4 + msg.length) + msg); // 0x11 = 17 MNG_KVM_MESSAGE
418 }
419
415 - obj.SendKeyMsgKC = function (action, kc) {
420 + obj.SendKeyMsgKC = function (action, kc, extendedKey) {
421 if (obj.State != 3) return;
417 - if (typeof action == 'object') { for (var i in action) { obj.SendKeyMsgKC(action[i][0], action[i][1]); } }
422 + if (typeof action == 'object') { for (var i in action) { obj.SendKeyMsgKC(action[i][0], action[i][1], action[i][2]); } }
423 else {
424 if (action == 1) { // Key Down
425 if (obj.pressedKeys.indexOf(kc) == -1) { obj.pressedKeys.unshift(kc); } // Add key press to start of array
@@ -422,9 +427,11 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
427 var i = obj.pressedKeys.indexOf(kc);
428 if (i != -1) { obj.pressedKeys.splice(i, 1); } // Remove the key press from the pressed array
429 }
425 -
430 if (obj.debugmode > 0) { console.log('Sending Key ' + kc + ', action ' + action); }
427 - obj.send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, (action - 1), kc));
431 +
432 + var up = (action - 1);
433 + if (extendedKey) { if (up == 1) { up = 3; } else { up = 4; } }
434 + obj.send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, up, kc));
435 }
436 }
437
@@ -563,13 +570,13 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
570 obj.xxMouseWheel = function (e) { if (obj.State == 3) { obj.SendMouseMsg(obj.KeyAction.SCROLL, e); return false; } return true; }
571 obj.xxKeyUp = function (e) {
572 if ((e.key != 'Dead') && (obj.State == 3)) {
566 - 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); }
573 + 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); }
574 }
575 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
576 }
577 obj.xxKeyDown = function (e) {
578 if ((e.key != 'Dead') && (obj.State == 3)) {
572 - if (!((typeof e.key == 'string') && (e.key.length == 1) && (e.ctrlKey != true) && (e.altKey != true) && ((obj.remoteKeyMap == false) || (obj.debugmode > 0)))) {
579 + 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))) {
580 obj.SendKeyMsg(obj.KeyAction.DOWN, e);
581 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
582 }
@@ -577,7 +584,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
584 }
585 obj.xxKeyPress = function (e) {
586 if ((e.key != 'Dead') && (obj.State == 3)) {
580 - 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); }
587 + 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); }
588 }
589 if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false;
590 }