summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/InputHandler.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/view/InputHandler.ts b/src/view/InputHandler.ts
index 86d4ec6..d06bcf8 100644
--- a/src/view/InputHandler.ts
+++ b/src/view/InputHandler.ts
@@ -13,8 +13,13 @@ class InputHandler {
this.listeners.forEach(l => l());
}
- constructor() {
+ constructor(private relevantKeys: {[key: number]: boolean}) {
window.addEventListener('keydown', (ev) => {
+ if (!relevantKeys[ev.keyCode])
+ return;
+
+ ev.preventDefault();
+
if (!this.keys[ev.keyCode]) {
this.keys[ev.keyCode] = true;
this.callListeners();
@@ -22,6 +27,11 @@ class InputHandler {
});
window.addEventListener('keyup', (ev) => {
+ if (!relevantKeys[ev.keyCode])
+ return;
+
+ ev.preventDefault();
+
if (this.keys[ev.keyCode]) {
delete this.keys[ev.keyCode];
this.callListeners();