Files
GameStarter/src/js/net/minecraft/util/Keyboard.js
T
LabyStudio 45961bbfbb convert classes to es6
(cherry picked from commit e7615d49a4071fe5b5f192884f142c9f3385211a)
2022-05-02 04:45:51 +02:00

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];
}
}