You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This page describes functions for registering and managing custom keybinds.
3
+
This page describes functions for registering and managing custom keybinds in the Lilia framework.
4
4
5
5
---
6
6
7
7
## Overview
8
8
9
-
The keybind library runs **client-side** and stores user-defined key bindings in `lia.keybind.stored`. Bindings are saved to `data/lilia/keybinds/<gamemode>/<server-ip>.json` (using the server IP with dots replaced by underscores) and loaded automatically on start. If a legacy `.txt` file exists it is migrated to the new JSON format. Press and release callbacks are dispatched through `PlayerButtonDown` and `PlayerButtonUp`, and a “Keybinds” page is added to the configuration menu via `PopulateConfigurationButtons`. Editing in this menu can be disabled with the `AllowKeybindEditing` configuration option.
9
+
The keybind library runs **client-side** and stores user-defined key bindings in `lia.keybind.stored`. Bindings are saved to `data/lilia/keybinds/<gamemode>/<server-ip>.json` (using the server IP with dots replaced by underscores) and loaded automatically on start. If a legacy `.txt` file exists it is migrated to the new JSON format.
10
+
11
+
Keybinds are triggered through `PlayerButtonDown` and `PlayerButtonUp` hooks, and a "Keybinds" page is added to the configuration menu via `PopulateConfigurationButtons`. Editing in this menu can be disabled with the `AllowKeybindEditing` configuration option.
10
12
11
13
Each entry in `lia.keybind.stored` contains:
12
14
13
-
*`default` (*number*) – key code assigned on registration.
14
-
*`value` (*number*) – current key code (initially the default).
15
-
*`callback` (*function | nil*) – invoked when the key is pressed. The player is passed as the sole argument.
16
-
*`release` (*function | nil*) – invoked when the key is released. The player is passed as the sole argument.
15
+
*`default` (*number*) – key code assigned on registration
16
+
*`value` (*number*) – current key code (initially the default)
17
+
*`callback` (*function | nil*) – invoked when the key is pressed
18
+
*`release` (*function | nil*) – invoked when the key is released
19
+
*`shouldRun` (*function | nil*) – optional validation function that must return true for the keybind to execute
20
+
*`serverOnly` (*boolean | nil*) – if true, the callback runs server-side via networking
17
21
18
-
Numeric key codes are also mapped back to their action identifiers for reverse lookup. The library registers some actions by default (e.g. `openInventory` and `adminMode`) but leaves them unbound.
22
+
The library also maintains reverse mappings from key codes to action identifiers for efficient lookup.
19
23
20
24
---
21
25
26
+
## Functions
27
+
22
28
### lia.keybind.add
23
29
24
30
**Purpose**
25
31
26
-
Register a keybind action and optional callbacks. The default key is stored and a reverse mapping from key code to action is created. Existing user selections are preserved.
32
+
Register a keybind action with callbacks and optional validation. The default key is stored and a reverse mapping from key code to action is created.
27
33
28
34
**Parameters**
29
35
30
36
*`k` (*string | number*): Key identifier. A string is matched case-insensitively against the internal key map. Invalid keys abort registration.
31
-
*`d` (*string*): Action identifier.
32
-
*`cb` (*function | nil*): Called when the key is pressed. Receives the player as its only argument. Optional.
33
-
*`rcb` (*function | nil*): Called when the key is released. Receives the player as its only argument. Optional.
37
+
*`d` (*string*): Action identifier (will be localized using `L()` function).
38
+
*`cb` (*table*): Callback table containing:
39
+
*`onPress` (*function*): Called when the key is pressed. Receives the player as its only argument.
40
+
*`onRelease` (*function | nil*): Called when the key is released. Receives the player as its only argument. Optional.
41
+
*`shouldRun` (*function | nil*): Validation function that must return true for the keybind to execute. Optional.
42
+
*`serverOnly` (*boolean | nil*): If true, the callback runs server-side via networking. Optional.
34
43
35
44
**Realm**
36
45
@@ -45,19 +54,43 @@ Register a keybind action and optional callbacks. The default key is stored and
0 commit comments