4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 dragonblocks.KeyHandler = class
30 this.downHandlers = {};
34 addEventListener("keydown", event => {
38 addEventListener("keyup", event => {
42 addEventListener("wheel", event => {
49 this.locked[key] = true;
54 for(let key in this.upHandlers)
57 for(let key in this.downHandlers)
63 dragonblocks.keyHandler.locked[key] = false;
68 for (let key in this.locked)
74 this.downHandlers[key] = func;
80 this.upHandlers[key] = func;
89 if (this.locked[event.key])
92 if (this.downHandlers[event.key]) {
93 event.preventDefault();
94 (this.downHandlers[event.key])();
99 if (this.locked[event.key])
102 if (this.upHandlers[event.key]){
103 event.preventDefault();
104 (this.upHandlers[event.key])();
109 if (this.locked["scroll"])
112 if (event.deltaY > 0 && this.downHandlers["scroll"]) {
113 event.preventDefault();
114 (this.downHandlers["scroll"])();
115 } else if (this.upHandlers["scroll"]) {
116 event.preventDefault();
117 (this.upHandlers["scroll"])();
124 dragonblocks.keyHandler = new dragonblocks.KeyHandler();
126 dragonblocks.registerOnStarted(_ => {
127 dragonblocks.keyHandler.unlockAll();