Function
bindKey
Binds a function or a command to a player's key. The function gets (on the server also the player) the key name, the state and the extra arguments from bindKey. Instead of a function you can pass a command name: the key runs it like /command. On the server the player's game watches the key and reports presses to the server.
Syntax
Server
bool bindKey(player thePlayer, string key, string keyState, function|string handler, ...)Client
bool bindKey(string key, string keyState, function|string handler, ...)Arguments
thePlayerplayer- The player (server only).
keystring- The key:
"a","F2","enter","mouse1","num_5"... keyStatestring"down"(press),"up"(release) or"both".handlerfunction|string- A function or a command name.
...any, optional- Arguments passed to the function.
Returns
true if the key was bound (the same function twice returns false).
Example
F2 opens and closes a menu with the cursor.
local open = false
bindKey("F2", "down", function()
open = not open
showCursor(open)
end)
See also
unbindKeyUnbinds a function or a command from a key. Without a function it removes everything from the key in that state, and without a state in both states.isKeyBoundChecks whether a function is bound to a key (a specific one or any).getKeyStateChecks whether a key is held down right now. Works withoutbindKeytoo, e.g. inonClientRender.addCommandHandlerRegisters a chat and console command (e.g./car). When a player types it, the function is called. On the server the function gets the player, the command name and the following words as separate arguments; on the client the command name and the words. One command can have several functions, also from different resources. The command goes away with the resource that added it.