diff options
author | Maxim Devaev <[email protected]> | 2022-09-21 15:42:23 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-09-21 15:42:23 +0300 |
commit | cb8534dfe72d0df4d13c36760c6d23bcd4bd0ff2 (patch) | |
tree | 2672f94a03300f000cc49f5b9ce756e07084723f /web | |
parent | 0ebd2da83d7441389f0a54ea47123acca5a8d4db (diff) |
refactoring
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/keypad.js | 18 | ||||
-rw-r--r-- | web/share/js/kvm/keyboard.js | 6 | ||||
-rw-r--r-- | web/share/js/kvm/mouse.js | 10 |
3 files changed, 19 insertions, 15 deletions
diff --git a/web/share/js/keypad.js b/web/share/js/keypad.js index 90c1e652..797a351e 100644 --- a/web/share/js/keypad.js +++ b/web/share/js/keypad.js @@ -88,13 +88,19 @@ export function Keypad(__keys_parent, __sendKey, __apply_fixes) { for (let dict of [__keys, __modifiers]) { for (let code in dict) { if (__isActive(dict[code][0])) { - self.emit(code, false); + self.emitByCode(code, false); } } } }; - self.emit = function(code, state, apply_fixes=true) { + self.emitByKeyEvent = function(event, state) { + if (!event.repeat) { + self.emitByCode(event.code, state); + } + }; + + self.emitByCode = function(code, state, apply_fixes=true) { if (code in __merged) { if (__fix_win_altgr && apply_fixes) { if (!__fixWinAltgr(code, state)) { @@ -116,7 +122,7 @@ export function Keypad(__keys_parent, __sendKey, __apply_fixes) { for (let code in __keys) { setTimeout(function() { if (__isActive(__keys[code][0])) { - self.emit(code, false, false); + self.emitByCode(code, false, false); } }, 100); } @@ -131,13 +137,13 @@ export function Keypad(__keys_parent, __sendKey, __apply_fixes) { clearTimeout(__altgr_ctrl_timer); __altgr_ctrl_timer = null; if (code !== "AltRight") { - self.emit("ControlLeft", true, false); + self.emitByCode("ControlLeft", true, false); } } if (code === "ControlLeft" && !__isActive(__modifiers["ControlLeft"][0])) { __altgr_ctrl_timer = setTimeout(function() { __altgr_ctrl_timer = null; - self.emit("ControlLeft", true, false); + self.emitByCode("ControlLeft", true, false); }, 50); return false; // Stop handling } @@ -145,7 +151,7 @@ export function Keypad(__keys_parent, __sendKey, __apply_fixes) { if (__altgr_ctrl_timer) { clearTimeout(__altgr_ctrl_timer); __altgr_ctrl_timer = null; - self.emit("ControlLeft", true, false); + self.emitByCode("ControlLeft", true, false); } } return true; // Continue handling diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js index 4b30b2c6..7f4c4f84 100644 --- a/web/share/js/kvm/keyboard.js +++ b/web/share/js/kvm/keyboard.js @@ -89,7 +89,7 @@ export function Keyboard(__recordWsEvent) { }; self.emit = function(code, state) { - __keyboardHandler({code: code}, state); + __keypad.emitByCode(code, state); }; var __updateOnlineLeds = function() { @@ -126,9 +126,7 @@ export function Keyboard(__recordWsEvent) { if (event.preventDefault) { event.preventDefault(); } - if (!event.repeat) { - __keypad.emit(event.code, state); - } + __keypad.emitByKeyEvent(event, state); }; var __sendKey = function(code, state) { diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index f927567c..703ea095 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -168,11 +168,11 @@ export function Mouse(__getGeometry, __recordWsEvent) { event.preventDefault(); if (__absolute || __isRelativeCaptured()) { switch (event.button) { - case 0: __keypad.emit("left", state); break; - case 2: __keypad.emit("right", state); break; - case 1: __keypad.emit("middle", state); break; - case 3: __keypad.emit("up", state); break; - case 4: __keypad.emit("down", state); break; + case 0: __keypad.emitByCode("left", state); break; + case 2: __keypad.emitByCode("right", state); break; + case 1: __keypad.emitByCode("middle", state); break; + case 3: __keypad.emitByCode("up", state); break; + case 4: __keypad.emitByCode("down", state); break; } } else if (!__absolute && !__isRelativeCaptured() && !state) { $("stream-box").requestPointerLock(); |