Input

Class Input

Namespace:

namespace Lenga\Engine\Core;

class Input

Methods

getAxis

public static function getAxis(string $axis)

Class Input

getAxisRaw

public static function getAxisRaw(string $axis)

Retrieves the raw value of the specified input axis.

getKey

public static function getKey(int|string|KeyCode $key)

Checks if the specified key is currently pressed.

getKeyDown

public static function getKeyDown(int|string|KeyCode $key)

Checks if the specified key was pressed down this frame.

getKeyUp

public static function getKeyUp(int|string|KeyCode $key)

Checks if the specified key was released this frame.

getButton

public static function getButton(string $axis)

Mirrors -style virtual buttons such as Jump.

getButtonDown

public static function getButtonDown(string $axis)

Mirrors -style virtual buttons such as Jump.

getButtonUp

public static function getButtonUp(string $axis)

Mirrors -style virtual buttons such as Jump.

isKeyPressed

public static function isKeyPressed(int|string|KeyCode $key)

Raylib-style alias for IsKeyPressed().

isKeyDown

public static function isKeyDown(int|string|KeyCode $key)

Raylib-style alias for IsKeyDown().

isKeyReleased

public static function isKeyReleased(int|string|KeyCode $key)

Raylib-style alias for IsKeyReleased().

isKeyUp

public static function isKeyUp(int|string|KeyCode $key)

Raylib-style alias for IsKeyUp().

isGamepadAvailable

public static function isGamepadAvailable(int $gamepad)

Mirrors raylib's IsGamepadAvailable().

getGamepadName

public static function getGamepadName(int $gamepad)

Mirrors raylib's GetGamepadName().

isGamepadButtonPressed

public static function isGamepadButtonPressed(int $gamepad, int|GamepadButton $button)

Mirrors raylib's IsGamepadButtonPressed().

isGamepadButtonDown

public static function isGamepadButtonDown(int $gamepad, int|GamepadButton $button)

Mirrors raylib's IsGamepadButtonDown().

isGamepadButtonReleased

public static function isGamepadButtonReleased(int $gamepad, int|GamepadButton $button)

Mirrors raylib's IsGamepadButtonReleased().

isGamepadButtonUp

public static function isGamepadButtonUp(int $gamepad, int|GamepadButton $button)

Mirrors raylib's IsGamepadButtonUp().

getGamepadButtonPressed

public static function getGamepadButtonPressed()

Mirrors raylib's GetGamepadButtonPressed().

getGamepadAxisCount

public static function getGamepadAxisCount(int $gamepad)

Mirrors raylib's GetGamepadAxisCount().

getGamepadAxisMovement

public static function getGamepadAxisMovement(int $gamepad, int|GamepadAxis $axis)

Mirrors raylib's GetGamepadAxisMovement().

setGamepadMappings

public static function setGamepadMappings(string $mappings)

Mirrors raylib's SetGamepadMappings().

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Input;
use Lenga\Engine\Core\KeyCode;

class PlayerController extends Behaviour
{
    public function update(): void
    {
        // Check for key presses
        if (Input::getKeyDown(KeyCode::W)) {
            Debug::log('W key pressed');
        }

        // Check if key is held down
        if (Input::getKey(KeyCode::SPACE)) {
            // Jump logic
        }

        // Use input axes for smooth movement
        $horizontalInput = Input::getAxis('Horizontal');
        $verticalInput = Input::getAxis('Vertical');

        // Check gamepad input
        if (Input::isGamepadAvailable(0)) {
            $gamepadAxis = Input::getGamepadAxisMovement(0, 0);
        }
    }
}