90ff4fe2ff
added changing maps all done like this https://www.youtube.com/watch?v=U7fYOnedjzs&list=PLcjhmZ8oLT0r9dSiIK6RB_PuBWlG1KSq_&index=9
26 lines
602 B
JavaScript
26 lines
602 B
JavaScript
class KeyPressListener {
|
|
constructor(keyCode, callback) {
|
|
let keySafe = true;
|
|
this.keydownFunction = function(event) {
|
|
if (event.code === keyCode) {
|
|
if (keySafe) {
|
|
keySafe = false;
|
|
callback();
|
|
}
|
|
}
|
|
};
|
|
this.keyupFunction = function(event) {
|
|
if (event.code === keyCode) {
|
|
keySafe = true;
|
|
}
|
|
};
|
|
|
|
document.addEventListener("keydown", this.keydownFunction);
|
|
document.addEventListener("keyup", this.keyupFunction);
|
|
}
|
|
|
|
unbind() {
|
|
document.removeEventListener("keydown", this.keydownFunction);
|
|
document.removeEventListener("keyup", this.keyupFunction);
|
|
}
|
|
} |