mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Basic implementations
This commit is contained in:
31
js/Key.js
Normal file
31
js/Key.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user