45961bbfbb
(cherry picked from commit e7615d49a4071fe5b5f192884f142c9f3385211a)
27 lines
575 B
JavaScript
27 lines
575 B
JavaScript
export default class Keyboard {
|
|
|
|
static state = {};
|
|
|
|
static create() {
|
|
window.addEventListener('keydown', function (event) {
|
|
Keyboard.state[event.code] = true;
|
|
});
|
|
window.addEventListener('keyup', function (event) {
|
|
event.preventDefault();
|
|
delete Keyboard.state[event.code];
|
|
});
|
|
};
|
|
|
|
static setState(key, state) {
|
|
Keyboard.state[key] = state;
|
|
}
|
|
|
|
static unPressAll() {
|
|
Keyboard.state = {};
|
|
}
|
|
|
|
static isKeyDown(key) {
|
|
return Keyboard.state[key];
|
|
}
|
|
|
|
} |