mr-crocs-adventures/js/Key.js

32 lines
654 B
JavaScript
Raw Normal View History

2023-09-18 22:33:55 +02:00
import {EventBus} from "./events/EventBus.js";
2020-01-22 22:50:45 +01:00
export default class Key
{
constructor(name)
{
this.name = name;
this.pressed = false;
2023-09-18 22:33:55 +02:00
EventBus.addEventListener(
2020-01-22 22:50:45 +01:00
'keydown',
(event) => {
if (event.code === this.name) {
this.pressed = true;
}
}
);
2023-09-18 22:33:55 +02:00
EventBus.addEventListener(
2020-01-22 22:50:45 +01:00
'keyup',
(event) => {
if (event.code === this.name) {
this.pressed = false;
}
}
);
}
isPressed()
{
return this.pressed;
}
}