扫码修改

lh_dev_ksck
yewj 6 months ago
parent 1ad2e2e5f2
commit de317f9591

@ -20,11 +20,13 @@ const KeyScaner = /** @class */ (function () {
this.dom = _dom; this.dom = _dom;
_dom.addEventListener('keydown', this.onKeyDown.bind(this)); _dom.addEventListener('keydown', this.onKeyDown.bind(this));
_dom.addEventListener('keyup', this.onKeyUp.bind(this)); _dom.addEventListener('keyup', this.onKeyUp.bind(this));
_dom.addEventListener('keypress', this.onKeyPress.bind(this));
this.interval = setInterval(this.onTick.bind(this), 100); this.interval = setInterval(this.onTick.bind(this), 100);
} }
KeyScaner.prototype.appendChar = function (c) { KeyScaner.prototype.appendChar = function (c) {
this.keybufs.push(c); this.keybufs.push(c);
// console.log('appendChar:', c, this.keybufs)
}; };
KeyScaner.prototype.onKeyDown = function (ev) { KeyScaner.prototype.onKeyDown = function (ev) {
this.lastTime = new Date().getTime(); this.lastTime = new Date().getTime();
@ -50,7 +52,7 @@ const KeyScaner = /** @class */ (function () {
} else { } else {
if (ev.key.length == 1) { if (ev.key.length == 1) {
var charCode = ev.key.charCodeAt(0); var charCode = ev.key.charCodeAt(0);
console.log("key="+charCode); // console.log("key="+charCode);
if (charCode >= 48 && charCode <= 57) { if (charCode >= 48 && charCode <= 57) {
if (ev.altKey) { if (ev.altKey) {
this.altBuf.push(ev.key); this.altBuf.push(ev.key);
@ -73,7 +75,14 @@ const KeyScaner = /** @class */ (function () {
}; };
KeyScaner.prototype.onKeyUp = function (ev) { KeyScaner.prototype.onKeyUp = function (ev) {
this.lastTime = new Date().getTime(); this.lastTime = new Date().getTime();
if (ev.key == "Alt") { if (ev.charCode === 29) {
var str = this.altBuf.join("");
var num = parseInt(str);
var c = String.fromCharCode(num);
this.appendChar(c);
this.altBuf = [];
console.log('onKeyUp success:', ev.charCode, this.keybufs);
} else if (ev.key == "Alt") {
if (this.altBuf && this.altBuf.length > 0) { if (this.altBuf && this.altBuf.length > 0) {
var str = this.altBuf.join(""); var str = this.altBuf.join("");
var num = parseInt(str); var num = parseInt(str);
@ -85,6 +94,27 @@ const KeyScaner = /** @class */ (function () {
this.isShift = false; this.isShift = false;
} }
}; };
KeyScaner.prototype.onKeyPress = function (ev) {
this.lastTime = new Date().getTime();
const char = String.fromCharCode(ev.charCode);
console.log('KeyPress:', ev.charCode, char);
/**
* if (ev.charCode === 29) {
this.appendChar(char);
// console.log('KeyPress success:', ev.charCode, this.keybufs);
} else
*/
if (char == '\n') {
this.completeInput();
}
// if (ev.charCode === 49) {
// const char = String.fromCharCode(ev.charCode);
// this.appendChar(char);
// }
};
KeyScaner.prototype.completeInput = function () { KeyScaner.prototype.completeInput = function () {
var text = this.keybufs.join(""); var text = this.keybufs.join("");
this.keybufs = []; this.keybufs = [];
@ -104,6 +134,7 @@ const KeyScaner = /** @class */ (function () {
KeyScaner.prototype.dispose = function () { KeyScaner.prototype.dispose = function () {
this.dom.removeEventListener('keydown', this.onKeyDown); this.dom.removeEventListener('keydown', this.onKeyDown);
this.dom.removeEventListener('keyup', this.onKeyUp); this.dom.removeEventListener('keyup', this.onKeyUp);
this.dom.removeEventListener('keypress', this.onKeyPress);
clearInterval(this.interval); clearInterval(this.interval);
}; };
return KeyScaner; return KeyScaner;

Loading…
Cancel
Save