mr-crocs-adventures/js/Key.js

32 lines
654 B
JavaScript

import {EventBus} from "./events/EventBus.js";
export default class Key
{
constructor(name)
{
this.name = name;
this.pressed = false;
EventBus.addEventListener(
'keydown',
(event) => {
if (event.code === this.name) {
this.pressed = true;
}
}
);
EventBus.addEventListener(
'keyup',
(event) => {
if (event.code === this.name) {
this.pressed = false;
}
}
);
}
isPressed()
{
return this.pressed;
}
}