Keybind Library
Keyboard binding registration, storage, and execution system for the Lilia framework.
Overview
The keybind library provides comprehensive functionality for managing keyboard bindings in the Lilia framework. It handles registration, storage, and execution of custom keybinds that can be triggered by players. The library supports both client-side and server-side keybind execution, with automatic networking for server-only keybinds. It includes persistent storage of keybind configurations, user interface for keybind management, and validation to prevent key conflicts. The library operates on both client and server sides, with the client handling input detection and UI, while the server processes server-only keybind actions. It ensures proper key mapping, callback execution, and provides a complete keybind management system for the gamemode.
lia.keybind.add(k, d, desc, cb)
Register a keybind action with callbacks and optional metadata.
During initialization to expose actions to the keybind system/UI.
Parameters:
string|number k Key code or key name (or actionName when using table config form).string|table d Action name or config table when first arg is action name.
string desc optional Description when using legacy signature.
table cb optional Callback table {onPress, onRelease, shouldRun, serverOnly}.
Example Usage:
-- Table-based registration with shouldRun and serverOnly.
lia.keybind.add("toggleMap", {
keyBind = KEY_M,
desc = "Open the world map",
serverOnly = false,
shouldRun = function(client) return client:Alive() end,
onPress = function(client)
if IsValid(client.mapPanel) then
client.mapPanel:Close()
client.mapPanel = nil
else
client.mapPanel = vgui.Create("liaWorldMap")
end
end
})
lia.keybind.get(a, df)
Get the key code assigned to an action, with default fallback.
When populating keybind UI or triggering actions manually.
Parameters:
string a Action name.number df optional Default key code if not set.
Returns:
number|nilExample Usage:
local key = lia.keybind.get("openInventory", KEY_I)
print("Inventory key is:", input.GetKeyName(key))
lia.keybind.save()
Persist current keybind overrides to disk.
After users change keybinds in the config UI.
Example Usage:
lia.keybind.save()
lia.keybind.load()
Load keybind overrides from disk, falling back to defaults if missing.
On client init/config load; rebuilds reverse lookup table for keys.
Example Usage:
hook.Add("Initialize", "LoadLiliaKeybinds", lia.keybind.load)