diff options
author | Maxim Devaev <[email protected]> | 2022-08-22 18:41:02 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-08-22 18:41:02 +0300 |
commit | 766e5151788655542d8a9f0bb74889d249c0a016 (patch) | |
tree | 55727598a8b25c03e50c929dbbaa905c425f2869 /web | |
parent | 7bd690b4db5a2f075c2b13432a983dad8fc86622 (diff) |
pikvm/pikvm#375: fixed AltGr handling
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/keypad.js | 50 | ||||
-rw-r--r-- | web/share/js/kvm/keyboard.js | 7 | ||||
-rw-r--r-- | web/share/js/kvm/mouse.js | 2 | ||||
-rw-r--r-- | web/share/js/tools.js | 4 |
4 files changed, 55 insertions, 8 deletions
diff --git a/web/share/js/keypad.js b/web/share/js/keypad.js index 39c4ab25..90c1e652 100644 --- a/web/share/js/keypad.js +++ b/web/share/js/keypad.js @@ -26,7 +26,7 @@ import {tools, $$$} from "./tools.js"; -export function Keypad(__keys_parent, __sendKey, __fix_mac_cmd=false) { +export function Keypad(__keys_parent, __sendKey, __apply_fixes) { var self = this; /************************************************************************/ @@ -35,7 +35,22 @@ export function Keypad(__keys_parent, __sendKey, __fix_mac_cmd=false) { var __keys = {}; var __modifiers = {}; + var __fix_mac_cmd = false; + var __fix_win_altgr = false; + var __altgr_ctrl_timer = null; + var __init__ = function() { + if (__apply_fixes) { + __fix_mac_cmd = tools.browser.is_mac; + if (__fix_mac_cmd) { + tools.info(`Keymap at ${__keys_parent}: enabled Fix-Mac-CMD`); + } + __fix_win_altgr = tools.browser.is_win; + if (__fix_win_altgr) { + tools.info(`Keymap at ${__keys_parent}: enabled Fix-Win-AltGr`); + } + } + for (let el_key of $$$(`${__keys_parent} div.key`)) { let code = el_key.getAttribute("data-code"); @@ -81,6 +96,11 @@ export function Keypad(__keys_parent, __sendKey, __fix_mac_cmd=false) { self.emit = function(code, state, apply_fixes=true) { if (code in __merged) { + if (__fix_win_altgr && apply_fixes) { + if (!__fixWinAltgr(code, state)) { + return; + } + } __commonHandler(__merged[code][0], state, false); if (__fix_mac_cmd && apply_fixes) { __fixMacCmd(); @@ -103,6 +123,34 @@ export function Keypad(__keys_parent, __sendKey, __fix_mac_cmd=false) { } }; + var __fixWinAltgr = function(code, state) { + // https://github.com/pikvm/pikvm/issues/375 + // https://github.com/novnc/noVNC/blob/84f102d6/core/input/keyboard.js + if (state) { + if (__altgr_ctrl_timer) { + clearTimeout(__altgr_ctrl_timer); + __altgr_ctrl_timer = null; + if (code !== "AltRight") { + self.emit("ControlLeft", true, false); + } + } + if (code === "ControlLeft" && !__isActive(__modifiers["ControlLeft"][0])) { + __altgr_ctrl_timer = setTimeout(function() { + __altgr_ctrl_timer = null; + self.emit("ControlLeft", true, false); + }, 50); + return false; // Stop handling + } + } else { + if (__altgr_ctrl_timer) { + clearTimeout(__altgr_ctrl_timer); + __altgr_ctrl_timer = null; + self.emit("ControlLeft", true, false); + } + } + return true; // Continue handling + }; + var __clickHandler = function(el_key, state) { __commonHandler(el_key, state, false); __unholdModifiers(); diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js index 0cdfafda..4b30b2c6 100644 --- a/web/share/js/kvm/keyboard.js +++ b/web/share/js/kvm/keyboard.js @@ -35,12 +35,7 @@ export function Keyboard(__recordWsEvent) { var __keypad = null; var __init__ = function() { - let fix_mac_cmd = tools.browser.is_mac; - if (fix_mac_cmd) { - tools.info("Keyboard: enabled Fix-Mac-CMD"); - } - - __keypad = new Keypad("div#keyboard-window", __sendKey, fix_mac_cmd); + __keypad = new Keypad("div#keyboard-window", __sendKey, true); $("hid-keyboard-led").title = "Keyboard free"; diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index 096eebc6..f927567c 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -48,7 +48,7 @@ export function Mouse(__getGeometry, __recordWsEvent) { var __stream_hovered = false; var __init__ = function() { - __keypad = new Keypad("div#stream-mouse-buttons", __sendButton); + __keypad = new Keypad("div#stream-mouse-buttons", __sendButton, false); $("hid-mouse-led").title = "Mouse free"; diff --git a/web/share/js/tools.js b/web/share/js/tools.js index 49a3f8c8..9fc6384c 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -388,6 +388,9 @@ export var tools = new function() { || "Unknown" ).indexOf("Mac") !== -1); + // Any Windows + let is_win = (navigator && !!(/win/i).exec(navigator.platform)); + return { "is_opera": is_opera, "is_firefox": is_firefox, @@ -396,6 +399,7 @@ export var tools = new function() { "is_blink": is_blink, "is_ios": is_ios, "is_mac": is_mac, + "is_win": is_win, }; }; self.info("Browser:", self.browser); |