Skip to content

Keybind

Keybind helpers for Lilia action registration, configurable key assignment, keybind persistence, reserved-key handling, and keybind configuration UI integration.


Overview

The keybind library centralizes shared and clientside keybind behavior under `lia.keybind`. It registers named actions with press and release callbacks, supports default and saved key codes, localizes action descriptions and categories, detects reserved Garry's Mod bind keys, saves and loads client keybind choices, and adds the keybind editor to the configuration menu.

lia.keybind.add(k, d, desc, cb)View Source

Purpose

Registers a keybind action and stores its default key, localized display metadata, press/release callbacks, optional run condition, and server-only behavior.

Realm

Shared

Parameters

string|number k The action name when using the configuration-table format, or the key code/key name when using the legacy argument format.

table|string d The keybind configuration table when k is an action name, or the action name when using the legacy argument format.

string desc optional Optional description used by the legacy argument format.

table cb optional Optional callback table used by the legacy argument format. Must include onPress and may include onRelease, shouldRun, and serverOnly.

Example Usage

  lia.keybind.add("toggleExample", {
      keyBind = KEY_F6,
      desc = "@toggleExampleDesc",
      category = "misc",
      onPress = function(client)
          client:notify("Pressed example keybind.")
      end
  })

lia.keybind.getDisplayDescription(action)View Source

Purpose

Gets the localized display description for a registered keybind action.

Realm

Shared

Parameters

string action The keybind action identifier.

Returns

string The localized action description, or an empty string if the action is not registered.

Example Usage

  local description = lia.keybind.getDisplayDescription("openInventory")

lia.keybind.getDisplayCategory(action)View Source

Purpose

Gets the localized display category for a registered keybind action.

Realm

Shared

Parameters

string action The keybind action identifier.

Returns

string The localized action category, or the localized miscellaneous category when no category is set.

Example Usage

  local category = lia.keybind.getDisplayCategory("openInventory")

lia.keybind.buildReservedKeys()View Source

Purpose

Builds the clientside reserved-key lookup from Garry's Mod default bindings and entries added through AddReservedKeybinds.

Realm

Client

Example Usage

  lia.keybind.buildReservedKeys()

lia.keybind.isKeyReserved(keyCode)View Source

Purpose

Checks whether a numeric key code is currently marked as reserved by the keybind system.

Realm

Client

Parameters

number keyCode The key code to check.

Returns

boolean True if the key is reserved, otherwise false.

Example Usage

  if lia.keybind.isKeyReserved(KEY_F1) then return end

lia.keybind.get(a, df)View Source

Purpose

Returns the selected key code for a registered keybind action, falling back to the action default or a provided fallback value.

Realm

Client

Parameters

string a The keybind action identifier.

any df Fallback value returned when the action is not registered or has no stored/default key.

Returns

any The selected key code, default key code, or fallback value.

Example Usage

  local keyCode = lia.keybind.get("openInventory", KEY_NONE)

lia.keybind.save()View Source

Purpose

Saves current clientside keybind values to `data/lilia/keybinds.json`.

Realm

Client

Example Usage

  lia.keybind.save()

lia.keybind.load()View Source

Purpose

Loads clientside keybind values from `data/lilia/keybinds.json`, applies defaults when no save exists, rebuilds numeric key lookups, rebuilds reserved keys, and runs InitializedKeybinds.

Realm

Client

Example Usage

  lia.keybind.load()

Hooks

Library-specific hooks documented for this library.


AddReservedKeybinds(reserved)View Source

Purpose

Allows plugins or modules to add extra reserved key codes before keybind choices are displayed.

Realm

Client

Parameters

table reserved Lookup table keyed by numeric key code. Set reserved[keyCode] to true to reserve a key.


InitializedKeybinds()View Source

Purpose

Runs after saved keybinds are loaded, numeric key lookups are rebuilt, and reserved keys are generated.

Realm

Client