File size: 613 Bytes
e6b949c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { InputHandler } from "./InputHandler";

class KeyboardManager implements InputHandler {
    private _keyMap: Map<string, (event: KeyboardEvent) => void>;

    constructor() {
        this._keyMap = new Map();
    }

    registerKey(key: string, callback: (event: KeyboardEvent) => void) {
        this._keyMap.set(key, callback);
    }

    unregisterKey(key: string) {
        this._keyMap.delete(key);
    }

    handleInput(event: KeyboardEvent) {
        const callback = this._keyMap.get(event.key);
        if (callback) {
            callback(event);
        }
    }
}

export { KeyboardManager };