← Back to Documentation Index

đŸ•šī¸ Input System

Keyboard, mouse, and gamepad input handling

📋 Overview

Unified input system supporting keyboard, mouse, and gamepad with button state tracking.

âŒ¨ī¸ Keyboard Functions

btn(buttonIndex)

Checks if a button is currently held down.

buttonIndex number (0-13) - Button index to check
Returns: boolean - true if button is held
Example:
if (btn(0)) player.x -= 2; // Move left
btnp(buttonIndex)

Checks if a button was just pressed (one-shot).

buttonIndex number (0-13) - Button index to check
Returns: boolean - true only on first frame of press
Example:
if (btnp(4)) player.jump(); // Jump on Z key press
isKeyDown(keyCode)

Checks if a specific keyboard key is currently held.

keyCode string - Key code (e.g., "w", "Space", "ArrowLeft")
Returns: boolean - true if key is held
Example:
if (isKeyDown("w")) player.moveForward();
isKeyPressed(keyCode)

Checks if a key was just pressed (one-shot).

keyCode string - Key code
Returns: boolean - true only on first frame
Example:
if (isKeyPressed("Enter")) selectMenuItem();

đŸ–ąī¸ Mouse Functions

mouseX()

Gets the current mouse X position (0-640).

Returns: number - Mouse X coordinate
Example:
const mx = mouseX();
mouseY()

Gets the current mouse Y position (0-360).

Returns: number - Mouse Y coordinate
Example:
const my = mouseY();
mouseDown()

Checks if mouse button is held.

Returns: boolean - true if mouse button is down
Example:
if (mouseDown()) dragObject();
mousePressed()

Checks if mouse button was just clicked (one-shot).

Returns: boolean - true only on first frame of click
Example:
if (mousePressed()) handleClick();

🎮 Gamepad Functions

gamepadConnected()

Checks if a gamepad is connected.

Returns: boolean - true if gamepad is connected
Example:
if (gamepadConnected()) useAnalogStick();
leftStickX()

Gets left analog stick X axis (-1.0 to 1.0).

Returns: number - Left stick X value with deadzone
Example:
player.x += leftStickX() * speed;
leftStickY()

Gets left analog stick Y axis (-1.0 to 1.0).

Returns: number - Left stick Y value with deadzone
Example:
player.y += leftStickY() * speed;
rightStickX()

Gets right analog stick X axis.

Returns: number - Right stick X value
Example:
camera.rotateY(rightStickX() * 0.05);
rightStickY()

Gets right analog stick Y axis.

Returns: number - Right stick Y value
Example:
camera.rotateX(rightStickY() * 0.05);