Define Key and KeySequence

This commit is contained in:
Shin'ya Ueoka 2019-05-18 21:43:56 +09:00
parent 2ec912c262
commit a5518dce3d
17 changed files with 207 additions and 222 deletions

View file

@ -1,5 +1,5 @@
import * as dom from '../shared/utils/dom';
import * as keys from '../shared/utils/keys';
import Key, * as keys from './domains/Key';
const cancelKey = (e: KeyboardEvent): boolean => {
return e.key === 'Escape' || e.key === '[' && e.ctrlKey;
@ -8,7 +8,7 @@ const cancelKey = (e: KeyboardEvent): boolean => {
export default class InputDriver {
private pressed: {[key: string]: string} = {};
private onKeyListeners: ((key: keys.Key) => boolean)[] = [];
private onKeyListeners: ((key: Key) => boolean)[] = [];
constructor(target: HTMLElement) {
this.pressed = {};
@ -19,7 +19,7 @@ export default class InputDriver {
target.addEventListener('keyup', this.onKeyUp.bind(this));
}
onKey(cb: (key: keys.Key) => boolean) {
onKey(cb: (key: Key) => boolean) {
this.onKeyListeners.push(cb);
}