GetKeyBoundToCommand: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Added a new, working example.) |
||
| Line 16: | Line 16: | ||
==Example== | ==Example== | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
This example adds a /getcommandbind command, allowing players to see what keys are bound to the given command. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | --This function is executed when the player uses the /getcommandbind [command] command. | ||
-- | --It outputs the key the command is bound to (if it is bound). | ||
local function playerCommand(_, command) | |||
if not command then --if no command name was given, output a syntax error message. | |||
outputChatBox("* Syntax: /getcommandbind [command name] .", 255, 0, 0) | |||
return | |||
end | |||
local keyName = getKeyBoundToCommand(command) | |||
if keyName then | |||
outputChatBox("* The command /"..command.." is bound to the "..keyName.." key.", 0, 0, 255) | |||
else | |||
outputChatBox("* The command /"..command.." is not bound to any keys.", 0, 0, 255) | |||
end | |||
end | end | ||
addCommandHandler("getcommandbind", playerCommand) | |||
addCommandHandler(" | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Revision as of 21:28, 15 November 2011
This function allow you get first key binded to command.
Syntax
string getKeyBoundToCommand( string command )
Required Arguments
- command: command what you need check.
Returns
Returns a string of first key binded to current command.
Example
Click to collapse [-]
ClientThis example adds a /getcommandbind command, allowing players to see what keys are bound to the given command.
--This function is executed when the player uses the /getcommandbind [command] command.
--It outputs the key the command is bound to (if it is bound).
local function playerCommand(_, command)
if not command then --if no command name was given, output a syntax error message.
outputChatBox("* Syntax: /getcommandbind [command name] .", 255, 0, 0)
return
end
local keyName = getKeyBoundToCommand(command)
if keyName then
outputChatBox("* The command /"..command.." is bound to the "..keyName.." key.", 0, 0, 255)
else
outputChatBox("* The command /"..command.." is not bound to any keys.", 0, 0, 255)
end
end
addCommandHandler("getcommandbind", playerCommand)
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey