Skip to main content

KeyboardInput

Provides a static interface for capturing and managing keyboard input events. It allows you to detect when keys are pressed, track currently pressed keys, and check if a key has been pressed for a specified duration.

start()

Starts capturing keyboard input.

Example:

Input.keyboard.start();

stop()

Stops capturing keyboard input.

Example:

Input.keyboard.stop();

pressedKeys(): string[]

Returns an array of currently pressed key codes.

Example:

const keys = Input.keyboard.pressedKeys();
console.log(keys);

isKeyReleased(key: string): boolean

Returns true only once if the key was previously pressed and then released.

Example:

if (Input.keyboard.isKeyReleased('Space')) {
console.log('Space key was released');
}

isKeyPressed(key: string): boolean

Checks if a specific key is currently pressed.

Example:

if (Input.keyboard.isKeyPressed('Enter')) {
console.log('Enter key is pressed');
}

isKeyPressedFor(key: string, durationInSeconds: number): boolean

Checks if a specific key has been pressed for a specified duration.

Example:

if (Input.keyboard.isKeyPressedFor('Shift', 2)) {
console.log('Shift key has been pressed for 2 seconds');
}