Skip to content

How to make custom keybinding

Batuhan Fatih Dilli edited this page Nov 11, 2026 · 6 revisions

In Outerra, keys are not written directly in the script. Instead there are 2 separate parts:

  • a config file that gives an action a name and a key, for example "the action open_menu is the key P"
  • a script (a game script or a vehicle script) that says what happens when that action is used, for example "open the menu"

This way the key and the code stay separate. The script only knows the action name, not the key. One action can also have more than one key, or a joystick button or axis.

On this page you will see how to add your own keys to a mod.

What is on this page:


1. How it works

  1. In your mod you create a config file with your actions. Every action has a name and one or more keys.
  2. In a script you register a function for that action name.
  3. When the player uses the key, Outerra calls your function.

The full name of an action has 3 parts:

ot / player / open_menu
 |      |         |
 |      |         action name
 |      group name
 config file name (ot.cfg)

You use this full name in the script. If one part is different, the function is never called.

There are 2 kinds of actions:

  • Events: something happens one time when the key is pressed, for example "open the menu".
  • Values: the action has a number, by default between -1 and 1. While the key is held, the number changes, for example the throttle of a vehicle goes up. If the action is on a joystick axis, the number is the axis position.

The script decides which kind it uses.


2. The config file

2.1 Where the file goes

A new mod doesn't have these folders and files, you need to create them yourself. Inside your mod, create a defaults folder, inside it an iomap folder, and inside that your config file:

game/mods/your_mod/
└── defaults/
    └── iomap/
        └── ot.cfg

The file name is the first part of the action name. Outerra has one file for every area, for example ot.cfg for the player and general keys, vehicle.cfg for vehicles and air.cfg for aircraft. If you put your keys in ot.cfg, your actions start with ot/.

You don't need to copy Outerra's default file. Your file only has your new actions, Outerra adds them to its own.

2.2 What is inside

The file is in JSON format. For example:

{
    "version": 1,
    "groups": [
        {
            "name": "player",
            "actions": [
                {
                    "name": "open_menu",
                    "bindings": [
                        { "event_name": "P" }
                    ]
                },
                {
                    "name": "show_info",
                    "bindings": [
                        { "event_name": "Z", "modifiers": "Ctrl" }
                    ]
                },
                {
                    "name": "reset_position",
                    "bindings": [
                        { "event_name": "X", "modifiers": "Alt Shift" }
                    ]
                }
            ]
        }
    ]
}
Field What it is
version version of the file format, it is 1
groups list of groups. A group is the second part of the action name
name (in a group) group name, here player
actions list of actions in this group
name (in an action) action name, the last part of the full name
bindings the keys for this action, there can be more than one
event_name the key, for example "P"
modifiers optional, keys that must be held together. One key like "Ctrl", or more with a space, like "Alt Shift"
mode optional, only for values: what the key does with the value

For the names of other keys, like "Space" or "F1", look at Outerra's default iomap files.

So in this example:

  • open_menu becomes ot/player/open_menu, key P
  • show_info becomes ot/player/show_info, key Ctrl + Z
  • reset_position becomes ot/player/reset_position, key Alt + Shift + X

2.3 Key modes

For values, every key can have a mode that says what the key does with the value:

Mode What the key does
+ (or empty) moves the value to +1
- moves the value to -1
0 moves the value back to 0
toggle switches between min and max
toggle+ switches between 0 and max
toggle- switches between min and 0

For example Outerra's ot/player/move has W with mode + (forward) and S with mode - (backward):

{
    "name": "move",
    "bindings": [
        { "event_name": "W", "mode": "+" },
        { "event_name": "S", "mode": "-" }
    ]
}

The mode only sets where the value should go. How fast it gets there, and the min and max values, are set in the script.


3. Events: keys that do something once

3.1 register_event

In the game script, in on_initialize(), call this.register_event() with the full action name and a function:

function on_initialize() {
    engine_module = this;

    // P: open a menu
    this.register_event("ot/player/open_menu", function () {
        engine_module.open_window("www/menu.html");
    });

    // Ctrl + Z: show a text on the screen
    this.register_event("ot/player/show_info", function () {
        engine_module.fade("Hello!");
    });

    return true;
}

When the player presses the key, Outerra calls the function. Inside the function, use engine_module to reach the game script, like in other functions outside on_initialize().

A vehicle script can register events the same way. In a vehicle script, put them in init_chassis(). This function runs one time for the vehicle model, so the keys are registered one time and work for every vehicle of that model.

3.2 Using actions that Outerra already has

You don't have to add every action to your config file. You can also register a function for an action that is already in Outerra's default file, for example:

// Left mouse button
this.register_event("ot/player/fire", function () {
    // ...
});

// V
this.register_event("ot/player/toggle_seat", function () {
    // ...
});

You can find all existing actions and their keys in Outerra's default iomap files.


4. Values: keys that change a value

Vehicles mostly use values, for example for the throttle or the steering.

4.1 register_axis

// In the vehicle script, inside init_chassis()

// Throttle: the value goes up while the key is held
this.register_axis("vehicle/controls/power", { vel: 0.5 }, throttle_action);

// Steering: the value goes from -1 to 1, and back to the center when the key is released
this.register_axis("vehicle/controls/steering", { vel: -0.8, acc: 50, center: -0.5 }, steering_action);

function throttle_action(v, dt) {
    // this refers to the vehicle instance, v is the current value of the action
    this.engine_load = v;
}

The function gets these values:

Parameter What it is
v the value of the action
dt time since the last frame, in seconds
ch channel number, see below

Channels: some actions can control more than one thing. For example, a plane with 2 engines can have one action to start the engines. The player can bind one key to engine 1, another key to engine 2, and a third key to both. When your function is called, ch tells you which one: 1 for engine 1, 2 for engine 2, and 0 for all of them. If your action controls only one thing, you can ignore ch.

4.2 Options

The second argument of register_axis says how the value changes when it is controlled with keys:

Option What it does
vel how fast the value changes per second while the key is held
acc how fast it reaches that speed after the key is pressed
center how fast the value goes back to 0 after the key is released. 0 means it stays where it is
minval lowest value, should be -1 or more (to work with joysticks)
maxval highest value, should be 1 or less
steps for keys that change the value in steps, how many steps there are between 0 and 1 (for example flaps)
channels how many extra channels the action supports, max 7

Negative vel or center: the minus doesn't mean the other direction. It means the speed depends on how fast the vehicle drives: when the vehicle stands, vel: -0.8 works like 0.8, and the faster the vehicle drives, the slower the value changes. This is useful for steering: at high speed the wheels turn slower, so the vehicle doesn't turn too sharply.

There is also register_switch(action, function), a short way to make an action that switches between 2 values, like lights on and off.


5. Common problems

Problem Reason
Pressing the key does nothing The full name in the script is not the same as in the config file. Check all 3 parts: file name, group name and action name
Pressing the key does nothing The config file is not in defaults/iomap of your mod
None of your keys work The JSON has an error, for example a missing comma or bracket
The key also does something else Outerra already uses this key for another action. Check Outerra's default files before you choose a key. Sharing a key is ok if the other action is not used at the same time, for example G is also ot/player/throw. If both actions are needed at the same time, choose a free key

Test

Clone this wiki locally