โŒจ๏ธ Key Maps, Touch, Gamepad and Engine Controls

This documentation explains how all GameCrom engine controls work: keyboard, multitouch, virtual joystick, mouse and gamepad.

New: Real multitouch system + OnKeyDown / OnKeyUp / OnKeyHold events

๐Ÿ“˜ Main Keys (e.key)

Keye.key value
UpArrowUp
DownArrowDown
LeftArrowLeft
RightArrowRight
Space" "
EnterEnter
EscapeEscape
Aโ€“Z"a" to "z"
0โ€“9"0" to "9"

๐ŸŸฆ Keyboard Events in Scripts

Object scripts can implement these functions:


// Key pressed
function OnKeyDown(obj, key) {
    Log("โ†“ " + key);
}

// Key held
function OnKeyHold(obj, key) {
    Log("โธ " + key);
}

// Key released
function OnKeyUp(obj, key) {
    Log("โ†‘ " + key);
}
These functions ONLY run if they are defined in the object's script.

๐Ÿ“Œ Example: Pause with Escape


function OnKeyDown(obj, key) {
    if (key === "escape") {
        let panel = getObjectByName("Panel");
        panel.active = !panel.active;

        if (panel.active) Pause();
        else Resume();
    }
}

๐Ÿ“ฑ Multitouch

Each finger becomes a "virtual key":

These virtual keys are sent to the same functions:


OnKeyDown(obj, "touch0")
OnKeyHold(obj, "touch0")
OnKeyUp(obj, "touch0")

Usage Example


function OnKeyHold(obj, key) {
    // Holding finger on screen
    if (key === "touch0") player.y -= 4;
    if (key === "touch1") player.y += 4;
}
This allows joystick + jump, twin-stick shooters, piano, drums, rhythm games, etc.

๐ŸŽฎ Gamepad (Xbox, PlayStation and generic)

Gamepad Buttons

ButtonIndex
A (Xbox) / X (PS)0
B / O1
X / โ–ก2
Y / โ–ณ3
L14
R15
L26
R27
Back / Share8
Start / Options9
Left Stick (button)10
Right Stick (button)11
Pad Up12
Pad Down13
Pad Left14
Pad Right15

๐Ÿ•น๏ธ Analog Sticks

StickIndexValues
Left X0-1 โ†’ 0 โ†’ +1
Left Y1-1 โ†’ 0 โ†’ +1
Right X2-1 โ†’ 0 โ†’ +1
Right Y3-1 โ†’ 0 โ†’ +1

Basic Example


const pads = navigator.getGamepads();
let p = pads[0];

if (p) {
    let x = p.axes[0];
    let y = p.axes[1];

    player.x += x * 4;
    player.y += y * 4;

    if (p.buttons[0].pressed) Jump();
}

๐ŸŽฎ Gamepad Name List for IsAnyPressed

The GameCrom engine automatically maps controller buttons and directions to standard names, so you can use them in:

This works the same on Xbox, PlayStation and generic controllers.

๐ŸŸฆ 1. D-Pad Directions

ActionName
Pad Upgamepad_up
Pad Downgamepad_down
Pad Leftgamepad_left
Pad Rightgamepad_right

๐ŸŸฉ 2. Main Buttons

ActionNameXboxPlayStation
A Buttongamepad_aAX
B Buttongamepad_bBO
X Buttongamepad_xXโ–ก
Y Buttongamepad_yYโ–ณ

๐ŸŸง 3. Shoulder Buttons / Triggers

ActionName
L1gamepad_l1
R1gamepad_r1
L2 (trigger)gamepad_l2
R2 (trigger)gamepad_r2

๐Ÿ“˜ 4. Special Buttons

ActionName
Startgamepad_start
Back / Sharegamepad_back
Left Stick Clickgamepad_ls_click
Right Stick Clickgamepad_rs_click

๐Ÿ•น๏ธ 5. Analog Sticks

Sticks are treated as analog axes, but they also have automatically mapped directions for IsAnyPressed:

DirectionName
Left Stick โ†’ leftgamepad_ls_left
Left Stick โ†’ rightgamepad_ls_right
Left Stick โ†’ upgamepad_ls_up
Left Stick โ†’ downgamepad_ls_down
Right Stick โ†’ leftgamepad_rs_left
Right Stick โ†’ rightgamepad_rs_right
Right Stick โ†’ upgamepad_rs_up
Right Stick โ†’ downgamepad_rs_down
Analog sticks remain analog (values from -1 to 1), but the engine activates these directions when passing a threshold value.

๐Ÿ“Œ Examples with IsAnyPressed

Console-style movement


// Move right with:
// โ†’ Key D
// โ†’ Right arrow
// โ†’ Gamepad right
// โ†’ Left or right stick pushed right
if (IsAnyPressed("d", "ArrowRight",
                 "gamepad_right",
                 "gamepad_ls_right",
                 "gamepad_rs_right")) {

    player.x += 5;
}

Jump with A / X / touch / space


if (IsAnyPressed(" ", "touch0", "gamepad_a")) {
    Jump();
}

Open menu


if (IsAnyPressed("escape", "gamepad_start")) {
    ToggleMenu();
}
Important: All these names work directly on: PC, mobile, PWA, iOS, Android and WebView.

๐ŸŸฆ IsAnyPressed โ€” Unified Input Detection

IsAnyPressed is an engine API function that checks if any of the keys, gamepad buttons or touch inputs is pressed in the current frame. It is the simplest way to mix keyboard, touch and gamepad without handling manual events.

๐Ÿ“Œ Syntax


IsAnyPressed(key1, key2, key3, ...)

๐Ÿ“˜ Basic Example


// Classic WASD + arrow movement
if (IsAnyPressed("ArrowUp", "w"))    player.y -= 4;
if (IsAnyPressed("ArrowDown", "s"))  player.y += 4;
if (IsAnyPressed("ArrowLeft", "a"))  player.x -= 4;
if (IsAnyPressed("ArrowRight", "d")) player.x += 4;

๐Ÿ“ฑ Combining keyboard + touch

The engineโ€™s multitouch system creates virtual keys: "touch0", "touch1", "touch2", etc.


// Jump with space or touching the screen
if (IsAnyPressed(" ", "touch0")) {
    Jump();
}

๐ŸŽฎ Combining keyboard + gamepad + touch


if (IsAnyPressed("ArrowRight", "d", "gamepad_right", "touch1")) {
    player.x += 5;
}

This lets different input methods perform the same action without duplicating code.

๐ŸŸฉ Example


function Update(obj, dt) {

    let speed = 200;

    // Move left with keyboard, controller or touch
    if (IsAnyPressed("ArrowLeft", "a", "gamepad_left", "touch1")) {
        obj.x -= speed * dt;
    }

    // Jump with space, gamepad A or main touch
    if (IsAnyPressed(" ", "gamepad_a", "touch0")) {
        Jump();
    }
}
Important: IsAnyPressed completely simplifies cross-browser and multiplatform control: PC, mobile, tablet, PWA and controllers.

๐ŸŸฅ IsJustPressed โ€” Single-press detection (edge)

IsJustPressed is a function of the GameCrom engine API that returns true only on the exact frame when a key, gamepad button, or touch input transitions from not pressed to pressed.

It is equivalent to the KeyDown or ButtonDown concept in engines like Unity.

Very important:
IsJustPressed is NOT held active.
It returns true only once, even if the button remains pressed.

๐Ÿ“Œ Syntax


IsJustPressed(key1, key2, key3, ...)
---

โŒจ๏ธ Keyboard example


// Fire only once when pressing space
if (IsJustPressed(" ")) {
    Shoot();
}
---

๐ŸŽฎ Gamepad example


// Fire only when pressing B (Xbox) / O (PlayStation)
if (IsJustPressed("gamepad_b")) {
    Shoot();
}
---

๐Ÿ“ฑ Touch example


// Action only when the screen is touched for the first time
if (IsJustPressed("touch0")) {
    Jump();
}
---

๐ŸŽฎโŒจ๏ธ๐Ÿ“ฑ Combined example (keyboard + gamepad + touch)


// Jump only once when pressing any of these
if (IsJustPressed(" ", "gamepad_a", "touch0")) {
    Jump();
}
---

๐Ÿง  Difference between IsAnyPressed and IsJustPressed

Function When it returns true Typical use
IsAnyPressed While the input is held Movement, continuous force
IsJustPressed Only on the first frame Shooting, jumping, menu
---

๐ŸŸฉ Recommended usage in Update


function Update(obj, dt) {

    // Continuous movement
    if (IsAnyPressed("ArrowRight", "d", "gamepad_right")) {
        obj.x += 200 * dt;
    }

    // Single action
    if (IsJustPressed(" ", "gamepad_a", "touch0")) {
        Jump();
    }
}
Recommendation:
Use IsAnyPressed for continuous actions
and IsJustPressed for instant actions.
Compatibility:
Works the same on PC, mobile, PWA, WebView, Android, iOS, and with Xbox / PlayStation / generic controllers.
Tip: You can mix keyboard, touch and gamepad with IsAnyPressed.