// @dynamic export class Keyboard { private static listeners = []; private static activeListener; private static keyMap = {}; static observe(keyCombination: Array, removeAfterCallback = true, callback: () => void): any { this.listeners.push({ combination: keyCombination, callback: callback, removeAfterCallback: removeAfterCallback }) } static onKeydown(event) { if (!this.listeners.length) return; this.keyMap[event.keyCode] = true; for (let i in this.listeners) { let check = true; this.activeListener = this.listeners[i]; for (let key of this.activeListener.combination) { if (!this.keyMap[key]) { check = false; break; } } if (check) { if (this.activeListener.removeAfterCallback) { for (let key of this.activeListener.combination) this.keyMap[key] = false; this.listeners.splice(parseInt(i), 1); } this.activeListener.callback(); } } } static onKeyUp(event) { this.keyMap[event.keyCode] = false; } // public static onRouteChange() { // if (this.activeListener && this.activeListener.removeAfterCallback) { // for (let i in this.listeners) { // var item = this.listeners[i]; // if (item.combination == this.activeListener.combination) this.listeners.splice(parseInt(i), 1); // } // } // } }