Input
Class Input
Namespace:
namespace Lenga\Engine\Core;
class Input
Static Properties
touchCount
public static int $touchCount
Number of touch snapshots captured for the current frame. The value is refreshed by the native runtime once per frame.
touches
/** @var list<Touch> */
public static array $touches
Touch snapshots captured for the current frame. Each entry is a Touch object.
touchPressureSupported
public static bool $touchPressureSupported
Whether the active backend reports real touch pressure values. Current raylib-backed builds report false.
touchSupported
public static bool $touchSupported
Whether the active backend reports touch input support.
Methods
getAxis
public static function getAxis(string $axis)
Returns the smoothed value of a named project input axis.
getAxisRaw
public static function getAxisRaw(string $axis)
Returns the raw value of a named project input axis before smoothing.
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)
Returns true while the named project input axis is pressed past its button threshold.
getButtonDown
public static function getButtonDown(string $axis)
Returns true on the frame the named project input axis crosses its button threshold.
getButtonUp
public static function getButtonUp(string $axis)
Returns true on the frame the named project input axis is released below its button threshold.
getMouseButton
public static function getMouseButton(int $button)
Returns whether the given mouse button is currently held.
getMouseButtonDown
public static function getMouseButtonDown(int $button)
Returns true during the frame the user pressed the given mouse button.
getMouseButtonUp
public static function getMouseButtonUp(int $button)
Returns true during the frame the user released the given mouse button.
getTouch
public static function getTouch(int $index)
Returns the Touch snapshot at the given frame-stable index.
isKeyPressed
public static function isKeyPressed(int|string|KeyCode $key)
Returns true on the frame the key is pressed.
isKeyDown
public static function isKeyDown(int|string|KeyCode $key)
Returns true while the key is held.
isKeyReleased
public static function isKeyReleased(int|string|KeyCode $key)
Returns true on the frame the key is released.
isKeyUp
public static function isKeyUp(int|string|KeyCode $key)
Returns true while the key is not held.
isGamepadAvailable
public static function isGamepadAvailable(int $gamepad)
Returns true when the gamepad slot has a connected gamepad.
getGamepadName
public static function getGamepadName(int $gamepad)
Returns the display name reported for the gamepad slot, or an empty string.
isGamepadButtonPressed
public static function isGamepadButtonPressed(int $gamepad, int|GamepadButton $button)
Returns true on the frame the gamepad button is pressed.
isGamepadButtonDown
public static function isGamepadButtonDown(int $gamepad, int|GamepadButton $button)
Returns true while the gamepad button is held.
isGamepadButtonReleased
public static function isGamepadButtonReleased(int $gamepad, int|GamepadButton $button)
Returns true on the frame the gamepad button is released.
isGamepadButtonUp
public static function isGamepadButtonUp(int $gamepad, int|GamepadButton $button)
Returns true while the gamepad button is not held.
getGamepadButtonPressed
public static function getGamepadButtonPressed()
Returns the most recent gamepad button pressed, or GamepadButton::UNKNOWN.
getGamepadAxisCount
public static function getGamepadAxisCount(int $gamepad)
Returns the number of axes exposed by the gamepad.
getGamepadAxisMovement
public static function getGamepadAxisMovement(int $gamepad, int|GamepadAxis $axis)
Returns the current movement value for a gamepad axis.
setGamepadMappings
public static function setGamepadMappings(string $mappings)
Loads additional gamepad mapping definitions and returns the number accepted.
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');
$lookX = Input::getAxis('Mouse X');
$lookY = Input::getAxis('Mouse Y');
if (Input::getButtonDown('Fire')) {
// Fire can be bound to a mouse button in Project > Input Settings.
}
// Check gamepad input
if (Input::isGamepadAvailable(0)) {
$gamepadAxis = Input::getGamepadAxisMovement(0, 0);
}
}
}