mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
fixed some keyboard corner cases
This commit is contained in:
parent
700b6b4619
commit
b7d933b6ce
@ -1,5 +1,6 @@
|
|||||||
var hid = new function() {
|
var hid = new function() {
|
||||||
var __install_timer = null;
|
var __install_timer = null;
|
||||||
|
var __installed = false;
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
keyboard.init();
|
keyboard.init();
|
||||||
@ -12,12 +13,7 @@ var hid = new function() {
|
|||||||
[[codes, true], [codes.slice().reverse(), false]].forEach(function(op) {
|
[[codes, true], [codes.slice().reverse(), false]].forEach(function(op) {
|
||||||
var [op_codes, state] = op;
|
var [op_codes, state] = op;
|
||||||
op_codes.forEach(function(code) {
|
op_codes.forEach(function(code) {
|
||||||
setTimeout(function() {
|
setTimeout(() => keyboard.fireEvent(code, state), delay);
|
||||||
document.dispatchEvent(new KeyboardEvent(
|
|
||||||
(state ? "keydown" : "keyup"),
|
|
||||||
{code: code},
|
|
||||||
));
|
|
||||||
}, delay);
|
|
||||||
delay += 100;
|
delay += 100;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -32,6 +28,7 @@ var hid = new function() {
|
|||||||
mouse.setSocket(ws);
|
mouse.setSocket(ws);
|
||||||
}
|
}
|
||||||
keyboard.setSocket(ws);
|
keyboard.setSocket(ws);
|
||||||
|
__installed = true;
|
||||||
} else {
|
} else {
|
||||||
tools.error("Can't resolve HID features:", http.responseText);
|
tools.error("Can't resolve HID features:", http.responseText);
|
||||||
__install_timer = setTimeout(() => hid.installCapture(ws), 1000);
|
__install_timer = setTimeout(() => hid.installCapture(ws), 1000);
|
||||||
@ -45,7 +42,10 @@ var hid = new function() {
|
|||||||
clearTimeout(__install_timer);
|
clearTimeout(__install_timer);
|
||||||
__install_timer = null;
|
__install_timer = null;
|
||||||
}
|
}
|
||||||
|
if (__installed) {
|
||||||
mouse.setSocket(null);
|
mouse.setSocket(null);
|
||||||
keyboard.setSocket(null);
|
keyboard.setSocket(null);
|
||||||
|
__installed = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
var keyboard = new function() {
|
var keyboard = new function() {
|
||||||
var __ws = null;
|
var __ws = null;
|
||||||
|
var __keys = [];
|
||||||
var __modifiers = [];
|
var __modifiers = [];
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
@ -9,6 +10,12 @@ var keyboard = new function() {
|
|||||||
Array.prototype.forEach.call(document.getElementsByClassName("key"), function(el_key) {
|
Array.prototype.forEach.call(document.getElementsByClassName("key"), function(el_key) {
|
||||||
el_key.onmousedown = () => __clickHandler(el_key, true);
|
el_key.onmousedown = () => __clickHandler(el_key, true);
|
||||||
el_key.onmouseup = () => __clickHandler(el_key, false);
|
el_key.onmouseup = () => __clickHandler(el_key, false);
|
||||||
|
el_key.onmouseout = function() {
|
||||||
|
if (__isPressed(el_key)) {
|
||||||
|
__clickHandler(el_key, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
__keys.push(el_key);
|
||||||
});
|
});
|
||||||
Array.prototype.forEach.call(document.getElementsByClassName("modifier"), function(el_key) {
|
Array.prototype.forEach.call(document.getElementsByClassName("modifier"), function(el_key) {
|
||||||
el_key.onmousedown = () => __toggleModifierHandler(el_key);
|
el_key.onmousedown = () => __toggleModifierHandler(el_key);
|
||||||
@ -17,10 +24,22 @@ var keyboard = new function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setSocket = function(ws) {
|
this.setSocket = function(ws) {
|
||||||
|
__keys.concat(__modifiers).forEach(function(el_key) {
|
||||||
|
if (__isActive(el_key)) {
|
||||||
|
keyboard.fireEvent(el_key.id, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
__ws = ws;
|
__ws = ws;
|
||||||
$("hid-keyboard-led").className = (ws ? "led-on" : "led-off");
|
$("hid-keyboard-led").className = (ws ? "led-on" : "led-off");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.fireEvent = function(code, state) {
|
||||||
|
document.dispatchEvent(new KeyboardEvent(
|
||||||
|
(state ? "keydown" : "keyup"),
|
||||||
|
{code: code},
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
var __keyboardHandler = function(event, state) {
|
var __keyboardHandler = function(event, state) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
el_key = $(event.code);
|
el_key = $(event.code);
|
||||||
@ -42,8 +61,7 @@ var keyboard = new function() {
|
|||||||
var __unholdModifiers = function() {
|
var __unholdModifiers = function() {
|
||||||
__modifiers.forEach(function(el_key) {
|
__modifiers.forEach(function(el_key) {
|
||||||
if (__isHolded(el_key)) {
|
if (__isHolded(el_key)) {
|
||||||
el_key.classList.remove("pressed");
|
__deactivate(el_key);
|
||||||
el_key.classList.remove("holded");
|
|
||||||
__sendKey(el_key.id, false);
|
__sendKey(el_key.id, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -51,22 +69,30 @@ var keyboard = new function() {
|
|||||||
|
|
||||||
var __commonHandler = function(el_key, state, cls) {
|
var __commonHandler = function(el_key, state, cls) {
|
||||||
if (state && !__isActive(el_key)) {
|
if (state && !__isActive(el_key)) {
|
||||||
el_key.classList.remove("holded");
|
__deactivate(el_key);
|
||||||
el_key.classList.add(cls);
|
el_key.classList.add(cls);
|
||||||
__sendKey(el_key.id, true);
|
__sendKey(el_key.id, true);
|
||||||
} else {
|
} else {
|
||||||
el_key.classList.remove("pressed");
|
__deactivate(el_key);
|
||||||
el_key.classList.remove("holded");
|
|
||||||
__sendKey(el_key.id, false);
|
__sendKey(el_key.id, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var __isPressed = function(el_key) {
|
||||||
|
return el_key.classList.contains("pressed");
|
||||||
|
};
|
||||||
|
|
||||||
var __isHolded = function(el_key) {
|
var __isHolded = function(el_key) {
|
||||||
return el_key.classList.contains("holded");
|
return el_key.classList.contains("holded");
|
||||||
};
|
};
|
||||||
|
|
||||||
var __isActive = function(el_key) {
|
var __isActive = function(el_key) {
|
||||||
return (el_key.classList.contains("pressed") || __isHolded(el_key));
|
return (__isPressed(el_key) || __isHolded(el_key));
|
||||||
|
};
|
||||||
|
|
||||||
|
var __deactivate = function(el_key) {
|
||||||
|
el_key.classList.remove("pressed");
|
||||||
|
el_key.classList.remove("holded");
|
||||||
};
|
};
|
||||||
|
|
||||||
var __sendKey = function(code, state) {
|
var __sendKey = function(code, state) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user