34 lines
767 B
JavaScript
34 lines
767 B
JavaScript
import Eventful from "zrender/src/mixin/Eventful";
|
|
|
|
export default class keyboardController extends Eventful {
|
|
constructor(ibp) {
|
|
super();
|
|
this.$ibp = ibp;
|
|
this.$zr = ibp.getZr();
|
|
this.events = ibp.getEvents();
|
|
this.initHandler(this.$zr);
|
|
}
|
|
|
|
initHandler(zr) {
|
|
if (zr) {
|
|
let keyActionHandler = this.keyAction.bind(this);
|
|
|
|
this.enable = (opt = {}) => {
|
|
window.addEventListener("keyup", keyActionHandler, false);
|
|
window.addEventListener("keydown", keyActionHandler, false);
|
|
};
|
|
|
|
this.disable = () => {
|
|
window.removeEventListener("keyup", keyActionHandler, false);
|
|
window.removeEventListener("keydown", keyActionHandler, false);
|
|
};
|
|
}
|
|
}
|
|
|
|
keyAction(e) {
|
|
if (!e.repeat) {
|
|
this.trigger(this.events.Keyboard, e);
|
|
}
|
|
}
|
|
}
|