mr-crocs-adventures/js/Key.js

32 lines
604 B
JavaScript
Raw Permalink Normal View History

2020-01-22 22:50:45 +01:00
export default class Key
{
constructor(name)
{
this.name = name;
this.pressed = false;
window.addEventListener(
'keydown',
(event) => {
if (event.code === this.name) {
this.pressed = true;
}
}
);
window.addEventListener(
'keyup',
(event) => {
if (event.code === this.name) {
this.pressed = false;
}
}
);
}
isPressed()
{
return this.pressed;
}
}