bindKey
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
Binds a player's key to a handler function or command, which will be called when the key is pressed.
Note
Using escape key or F8 key will always return false. Use onClientKey event instead.
Note
Handler function won't be triggered while focused in CEGUI editbox. You can use guiSetInputMode or onClientKey in order to fix that.
Syntax
bool bindKey ( string key, string keyState, string commandName, string arguments )Required Arguments
- key: The key or control you wish to bind to the command. See key names for a list of possible keys.
- keyState: A string that has one of the following values: "up": If the bound key should trigger the function when the key is released "down": If the bound key should trigger the function when the key is pressed "both": If the bound key should trigger the function when the key is pressed or released
- commandName: The name of the command that the key should be binded to.
- arguments:
Returns
- bool: value
Returns true if the key was bound, false otherwise.
Code Examples
client
This example will bind a player's 'F1' key and 'fire' control to 1 input function, clientside.
function funcInput ( key, keyState ) outputChatBox( "You " .. (keyState == "down" and "pressed" or "let go of") .. " the " .. key .. " key!" )end
function bindTheKeys ( commandName ) bindKey( "F1", "down", funcInput ) -- bind the player's F1 down key bindKey( "F1", "up", funcInput ) -- bind the player's F1 up key bindKey( "fire", "both", funcInput ) -- bind the player's fire down and up controlendaddCommandHandler ( "bindme", bindTheKeys )See Also
Input Functions
- addCommandHandler
- bindKey
- executeCommandHandler
- getAnalogControlState
- getBoundKeys
- getCommandHandlers
- getCommandsBoundToKey
- getFunctionsBoundToKey
- getKeyBoundToCommand
- getKeyBoundToFunction
- getKeyState
- isCapsLockEnabled
- isControlEnabled
- isKeyBound
- removeCommandHandler
- setAnalogControlState
- toggleAllControls
- toggleControl
- unbindKey
Input Events
- onClientCharacter
- onClientClick
- onClientCursorMove
- onClientDoubleClick
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientKey
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
- onClientPaste