tw.rawKeys
Side: Client
Raw keyboard input handling with QWERTY/AZERTY layout support.
ConVars
| ConVar | Default | Description |
|---|---|---|
twinded_libs:keyboard_layout | "qwerty" | Keyboard layout ("qwerty" or "azerty") |
Functions
tw.rawKeys.listen(key, callback) -> id
Registers a listener for a specific key press/release. Returns an ID that can be used to remove the listener.
| Parameter | Type | Description |
|---|---|---|
key | string or integer | Key name (e.g. "E", "SPACE") or VK code |
callback | function | Called with is_pressed (boolean): true on key down, false on key up |
Returns: integer — Listener ID
local id = tw.rawKeys.listen("E", function(is_pressed)
if is_pressed then
print("E key pressed")
else
print("E key released")
end
end)tw.rawKeys.removeListener(id) -> boolean
Removes a previously registered key listener.
| Parameter | Type | Description |
|---|---|---|
id | integer | Listener ID returned by listen |
Returns: boolean — true if the listener was found and removed.
local removed = tw.rawKeys.removeListener(id)tw.rawKeys.getKeyFromVK(vk_code) -> string | nil
Converts a virtual key code to a key name based on the current keyboard layout.
| Parameter | Type | Description |
|---|---|---|
vk_code | integer | Virtual key code |
Returns: string or nil — Key name, or nil if unknown.
local key_name = tw.rawKeys.getKeyFromVK(0x45) -- "E"tw.rawKeys.getAliasFromStandardKey(key) -> string
Returns the layout-adjusted alias for a standard QWERTY key name. For example, on AZERTY layout, "Q" returns "A".
| Parameter | Type | Description |
|---|---|---|
key | string | Standard QWERTY key name |
Returns: string — Adjusted key name for the current layout.
local adjusted = tw.rawKeys.getAliasFromStandardKey("Q")
-- "Q" on QWERTY, "A" on AZERTYtw.rawKeys.getAllVK() -> table
Returns a table of all known virtual key codes and their key names.
Returns: table — Key-value table mapping VK codes to key names.
local all_keys = tw.rawKeys.getAllVK()
for vk, name in pairs(all_keys) do
print(vk, name)
endExamples
Toggle a feature with a key
local feature_active = false
tw.rawKeys.listen("F5", function(is_pressed)
if is_pressed then
feature_active = not feature_active
print("Feature:", feature_active and "ON" or "OFF")
end
end)Temporary key listener
local id = tw.rawKeys.listen("G", function(is_pressed)
if is_pressed then
print("G pressed!")
end
end)
-- Later, remove the listener
tw.rawKeys.removeListener(id)AZERTY-aware key binding
-- This works correctly on both QWERTY and AZERTY layouts
local key = tw.rawKeys.getAliasFromStandardKey("E")
tw.rawKeys.listen(key, function(is_pressed)
if is_pressed then
-- interact
end
end)Notes
- The keyboard layout is read from the
twinded_libs:keyboard_layoutConVar. Players using AZERTY should set this in their server config or client settings. - Callbacks receive both press and release events. Check the
is_pressedparameter to distinguish them. - Listener IDs are stable and unique. Store them if you need to remove listeners later.
- Key names are case-insensitive strings (e.g.
"E","SPACE","F5","LSHIFT").

