KeyCode

Namespace:

namespace Lenga\Engine\Enumerations;

Identifies a physical keyboard key. Pass a KeyCode case to Input::getKey(), Input::getKeyDown(), and Input::getKeyUp() for type-safe key checks.

Common values

Case String value Description
BACKSPACE 'Backspace' Backspace key.
TAB 'Tab' Tab key.
ENTER 'Enter' Enter / Return key.
SHIFT 'Shift' Left Shift key.
CONTROL 'Control' Left Control key.
ALT 'Alt' Left Alt key.
ESCAPE 'Escape' Escape key.
SPACE 'Space' Space bar.
LEFT_ARROW 'LeftArrow' Left arrow key.
RIGHT_ARROW 'RightArrow' Right arrow key.
UP_ARROW 'UpArrow' Up arrow key.
DOWN_ARROW 'DownArrow' Down arrow key.
AZ 'A''Z' Letter keys.
ZERONINE '0''9' Number row keys.
F1F12 'F1''F12' Function keys.

Example

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

class PlayerController extends Behaviour
{
    public float $speed = 5.0;

    public function update(): void
    {
        $moveX = 0.0;
        $moveZ = 0.0;

        if (Input::getKey(KeyCode::A) || Input::getKey(KeyCode::LEFT_ARROW)) {
            $moveX = -1.0;
        } elseif (Input::getKey(KeyCode::D) || Input::getKey(KeyCode::RIGHT_ARROW)) {
            $moveX = 1.0;
        }

        if (Input::getKey(KeyCode::W) || Input::getKey(KeyCode::UP_ARROW)) {
            $moveZ = 1.0;
        } elseif (Input::getKey(KeyCode::S) || Input::getKey(KeyCode::DOWN_ARROW)) {
            $moveZ = -1.0;
        }

        $this->transform->translate([
            $moveX * $this->speed * Time::deltaTime(),
            0,
            $moveZ * $this->speed * Time::deltaTime(),
        ]);
    }
}

Methods

toRaylibKeyCode

public function toRaylibKeyCode(): int

Returns the underlying Raylib key code integer for this KeyCode case. Intended for engine-internal use.

resolve

public static function resolve(self|string|int $key): ?int

Converts a KeyCode case, a string key name, or a raw integer to its Raylib key code. Returns null if the key cannot be resolved.