Input Subsystem (`engine.Input`)

Poll real-time input states for the keyboard, mouse cursor coordinates, and button clicks without polling delay.

Functions Reference

Function Signature Description
engine.Input.isKeyDown(key) (int) → bool Returns true if the specified keyboard key is currently held down.
engine.Input.isMouseButtonDown(btn) (int) → bool Returns true if mouse button btn (0 = Left, 1 = Right, 2 = Middle) is pressed.
engine.Input.getMousePos() () → (num, num) Returns x, y coordinates of the mouse cursor relative to the window client area.

Common Keyboard Constants (GLFW)

Key Code Key Code Key Code
W 87 Up Arrow 265 Space 32
A 65 Down Arrow 264 Enter 257
S 83 Left Arrow 263 Escape 256
D 68 Right Arrow 262 Left Shift 340

Player Movement Controller Example

player_controller.lua
import engine

function updatePlayer(dt) {
    speed = 250
    dx, dy = 0, 0

    if (engine.Input.isKeyDown(87)) { dy = dy - 1 } -- W
    if (engine.Input.isKeyDown(83)) { dy = dy + 1 } -- S
    if (engine.Input.isKeyDown(65)) { dx = dx - 1 } -- A
    if (engine.Input.isKeyDown(68)) { dx = dx + 1 } -- D

    player.x = player.x + dx * speed * dt
    player.y = player.y + dy * speed * dt

    -- Mouse aiming:
    mx, my = engine.Input.getMousePos()
    aimAngle = math.atan(my - player.y, mx - player.x)
}