DOM. KeyboardManager

Manages the keyboard input.

Constructor

new KeyboardManager()

Examples
const { left } = DOM.KeyboardManagerInstance.keys;
if (DOM.KeyboardManagerInstance.isKeyPressed(left)) console.log("Left");
import { DOM } from "201flaviosilva-labs";
const { KEYS, KeyboardManager, KeyboardManagerInstance } = DOM;
setInterval(() => console.log(KeyboardManagerInstance.isKeyPressed(KEYS.a)), 100);
KeyboardManagerInstance.events.on("keyDown-left", () => console.log("down-left"));
KeyboardManagerInstance.events.on("keyUp-up", () => console.log(`up-${KEYS.up}`));

Members

(static) this.events

A event system to get on a key is pressed

Examples
DOM.KeyboardManagerInstance.events.on("keyDown-left", () => console.log("down -> left"));
DOM.KeyboardManagerInstance.events.on("keyUp-left", () => console.log("up -> left"));

(static) this.isPressed

All pressed keys will appear here

Examples
console.log(DOM.KeyboardManagerInstance.isPressed["left"]);
console.log(DOM.KeyboardManagerInstance.isPressed[DOM.KeyboardManagerInstance.getNameByKeyCode(37)]);

Methods

(static) KeyboardManager#getKeyCodeByName(name) → {number}

Returns the key code of the key by its name.

Parameters:
NameTypeDescription
namestring

The name of the key.

Returns:

The key code of the key.

Type: 
number
Example
console.log(DOM.KeyboardManagerInstance.getKeyCodeByName("left")); // 37

(static) KeyboardManager#getNameByKeyCode(keyCode) → {string}

Returns the name of the key by its keyCode.

Parameters:
NameTypeDescription
keyCodenumber

The key code of the key.

Returns:

The name of the key.

Type: 
string
Example
const { left } = DOM.KeyboardManagerInstance.keys;
console.log(DOM.KeyboardManagerInstance.getNameByKeyCode(left)); // left

(static) KeyboardManager#isKeyPressed(key) → {boolean}

Returns true if the key is pressed.

Parameters:
NameTypeDescription
keynumber | string

The key code or name of the key.

Returns:

True if the key is pressed.

Type: 
boolean
Example
const { left } = DOM.KeyboardManagerInstance.keys;
DOM.KeyboardManagerInstance.isKeyPressed(left); // false

(static) KeyboardManager#isKeyPressedKeyCode(keyCode) → {boolean}

Returns true if the key is pressed by its key code.

Parameters:
NameTypeDescription
keyCodenumber

The key code of the key.

Returns:

True if the key is pressed.

Type: 
boolean
Example
DOM.KeyboardManagerInstance.isKeyPressedKeyCode(37); // true

(static) KeyboardManager#isKeyPressedName(name) → {boolean}

Returns true if the key is pressed by its name.

Parameters:
NameTypeDescription
namestring

The name of the key.

Returns:

True if the key is pressed.

Type: 
boolean
Example
DOM.KeyboardManagerInstance.isKeyPressedName("left"); // true