mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
pikvm/pikvm#375: fixed AltGr handling
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user