mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 11:01:53 +08:00
big js refactoring
This commit is contained in:
27
kvmd/web/js/keyboard.js
Normal file
27
kvmd/web/js/keyboard.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var keyboard = new function() {
|
||||
this.installCapture = function(ws) {
|
||||
// https://www.codeday.top/2017/05/03/24906.html
|
||||
tools.info("Installing keyboard capture ...")
|
||||
document.onkeydown = (event) => __keyHandler(ws, event, true);
|
||||
document.onkeyup = (event) => __keyHandler(ws, event, false);
|
||||
$("hid-keyboard-led").className = "led-on";
|
||||
};
|
||||
|
||||
this.clearCapture = function() {
|
||||
tools.info("Removing keyboard capture ...")
|
||||
document.onkeydown = null;
|
||||
document.onkeyup = null;
|
||||
$("hid-keyboard-led").className = "led-off";
|
||||
};
|
||||
|
||||
var __keyHandler = function(ws, event, state) {
|
||||
// https://github.com/wesbos/keycodes/blob/gh-pages/scripts.js
|
||||
tools.debug("Key", (state ? "pressed:" : "released:"), event)
|
||||
event.preventDefault();
|
||||
ws.send(JSON.stringify({
|
||||
event_type: "key",
|
||||
key: event.code,
|
||||
state: state,
|
||||
}));
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user