UnbindKey: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(→Syntax) |
||
Line 10: | Line 10: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool unbindKey ( player thePlayer, string key [, string keyState, function handler | bool unbindKey ( player thePlayer, string key [, string keyState, function handler ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 10:38, 17 August 2020
Removes an existing key bind from the specified player.
Syntax
Click to collapse [-]
Serverbool unbindKey ( player thePlayer, string key, string keyState, string command )
bool unbindKey ( player thePlayer, string key [, string keyState, function handler ] )
Required Arguments
- thePlayer: The player you wish to unbind the key of.
- key: The key you wish to unbind. See Key names for a list of valid key names.
- keyState: Can be either:
- "up": If the bound key triggered a function when the key was released
- "down": If the bound key triggered a function when the key was pressed
- "both": If the bound key triggered a function when the key was pressed and released
- command : (Syntax 1) The command you wish to unbind.
Optional Arguments
- keyState: is optional in Syntax 2.
- handler: (Syntax 2) The function you wish to unbind.
Note: If you do not specify handler, any instances of key being bound will be unbound, whatever function they are bound to.
Returns
Returns 'true if the key was unbound, false if it was not previously bound or invalid arguments were passed to the function.
Click to collapse [-]
Clientbool unbindKey ( string key, string keyState, string command )
bool unbindKey ( string key [, string keyState, function handler ] )
Required Arguments
- key: The key you wish to unbind. See Key names for a list of valid key names.
- keyState: Can be either:
- "up": If the bound key triggered a function when the key was released
- "down": If the bound key triggered a function when the key was pressed
- "both": If the bound key triggered a function when the key was pressed and released
- command : (Syntax 1) The command you wish to unbind.
Optional Arguments
- keyState: is optional in Syntax 2.
- handler: (Syntax 2) The function you wish to unbind.
Note: If you do not specify handler, any instances of key being bound will be unbound, whatever function they are bound to.
Returns
Returns 'true if the key was unbound, false if it was not previously bound or invalid arguments were passed to the function.
Example
Click to collapse [-]
ServerThis function binds the player's F1 key to a function goMoo which outputs a chat message when pressed. The key is then unbound so that it can effectively only be used once per life.
-- define the function that will be called when F1 is pressed function goMoo( player ) outputChatBox ( getPlayerName ( player ) .. " says Mooooooo!" ) unbindKey ( player, "F1", "down", goMoo ) -- this function will no longer be triggered by the player, after removing the bind. end function playerSpawn ( ) bindKey ( source, "F1", "down", goMoo ) -- bind the player's F1 key to the 'goMoo' function defined above end addEventHandler ( "onPlayerSpawn", getRootElement(), playerSpawn ) -- make the playerSpawn function be called when a player spawns
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey