IsKeyBound: Difference between revisions
Jump to navigation
Jump to search
(→Example: added) |
mNo edit summary |
||
Line 19: | Line 19: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
This function kicks a player when he joins and numpad 9 is binded, and blame anyone random in the server! | -- This function kicks a player when he joins and numpad 9 is binded, and blame anyone random in the server! | ||
function onPlayerJoin () -- BE WARNED! never use the same function for the same event | function onPlayerJoin () -- BE WARNED! never use the same function for the same event | ||
if (isKeyBound (source,"num_9")) then -- if num pad 9 is binded | if (isKeyBound (source,"num_9")) then -- if num pad 9 is binded | ||
outputChatBox (getPlayerName (source) .. " has binded | outputChatBox (getPlayerName (source) .. " has binded numpad 9!",getRootElement(),255,0,0,false) -- let see everybody that he has binded it | ||
end | end | ||
end | end | ||
Line 31: | Line 30: | ||
==See Also== | ==See Also== | ||
{{Input functions}} | {{Input functions}} | ||
Revision as of 22:26, 5 May 2010
This function can be used to find out if a key has already been bound.
Syntax
bool isKeyBound ( player thePlayer, string key, [ string keyState, function handler ] )
Required Arguments
- thePlayer: The player you're checking.
- key: The key you're checking. See Key names for a list of valid key names.
Optional Arguments
- keyState: Is the state of the key when it calls the function, Can be either:
- "up": when the key is released
- "down": when the key is pressed
- handler: The function you're checking against
Note: If you do not specify a keyState or handler, any instances of key being bound will cause isKeyBound to return true.
Example
-- This function kicks a player when he joins and numpad 9 is binded, and blame anyone random in the server! function onPlayerJoin () -- BE WARNED! never use the same function for the same event if (isKeyBound (source,"num_9")) then -- if num pad 9 is binded outputChatBox (getPlayerName (source) .. " has binded numpad 9!",getRootElement(),255,0,0,false) -- let see everybody that he has binded it end end addEventHandler ("onPlayerJoin",getRootElement(),onPlayerJoin) -- add event.
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey