Atom Engine

Input

Purpose

The Input class is a high-level wrapper around a low-level input system. It manages keyboard state tracking, including key presses and held states, while optionally filtering out “blocked” keys (e.g., arrow keys, space, and specific action keys). It provides a simplified API for querying input state in game loops or interactive applications.


Lifecycle

Creation → Update → Destruction


Public API

constructor(blockedKeys?: string[])

Creates a new input handler instance.


isDown(key: string): boolean

Checks whether a key is currently being held down.


isPressed(key: string): boolean

Checks whether a key was pressed during the current update cycle.


clearPressed(): void

Resets all “pressed” states.


getState(): InputState

Returns the underlying input state object.


Internal Behavior


Example

import { Input } from "./Input";

const input = new Input();

// Game loop
function update() {
    if (input.isDown("ArrowLeft")) {
        console.log("Moving left continuously");
    }

    if (input.isPressed(" ")) {
        console.log("Jump triggered");
    }

    // Reset per-frame press states
    input.clearPressed();
}