Documentation
ModdingKeybinding

Creating a Keybinding

Register input bindings with typed callbacks

Edit nox.mod.json

{
  "type": "mod",
  "id": "my.mod",
  "version": "1.0.0",
  "relations": [
    {
      "id": "keybinding",
      "type": "depends",
      "version": ">=1.0.0",
      "register": "git+https://github.com/AtelierVR/nox.keybinding.git"
    }
  ],
  "constraints": [
    { "type": "after", "id": "keybinding" }
  ]
}

Create the .asmdef

{
  "name": "My.Mod",
  "references": [
    "Nox.KeyBinding"
  ]
}

Register

using Nox.KeyBindings;

public class Main : IMainModInitializer {
    private IKeyBinding _jump;
    private float _jumpValue;

    public void OnInitializeMain(IMainModCoreAPI api) {
        Instance = this;
        CoreAPI = api;
        var kb = api.ModAPI
            .GetMod("keybinding")
            ?.GetInstance<IKeyBindingManager>();
        _jump = kb.AddKeyBinding("jump", "<Keyboard>/space", "movement");
        _jump.AddListener<float>(v =>
            _jumpValue = v);
    }

    public void OnDisposeMain() {
        _jump?.RemoveListener<float>(v =>
            _jumpValue = v);
        Instance = null;
        CoreAPI = null;
    }
}

IKeyBindingManager

IKeyBinding AddKeyBinding(string id, string binding, string category = null);
IKeyBinding GetKeyBinding(string id, string category = null);
bool RemoveKeyBinding(string id, string category = null);

IKeyBinding

string GetId();
string GetCategory();
InputAction GetAction();
bool IsOverridden();
void AddListener<T>(Action<T> action) where T : struct;
void RemoveListener<T>(Action<T> action) where T : struct;

Overrides stored at settings.key_bindings.\{category\}.\{id\}.

On this page