GetBoundKeys: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{New feature|2|DP2|
__NOTOC__
This function does not exist in DP1.
{{Client function}}
}}
Returns a list of key names that are bound to the specified game [[Control names|control]] or console command.
 
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getBoundKeys ( string command/control )
table getBoundKeys ( string command/control )
</syntaxhighlight>
</syntaxhighlight>
===Required Arguments===
*'''command/control:''' the name of a game control or a console command. See the [[control names]] page for valid controls.
===Returns===
If one or more keys are bound to the specified control or console command, a table is returned containing the names of all the bound keys. If no keys are bound or an invalid name was passed, returns ''false''.
==Example==
This code adds a command handler with which you can check out the keybinds for any game control. As an example, typing "/keys forwards" would list all the keys which you can press to make the player walk forward.
<syntaxhighlight lang="lua">
function keysCommand ( command, controlName )
    if not controlName then                    -- make sure they specified a control name
        outputChatBox ( "No control name specified", 255, 0, 0 )
        return
    end
    local keys = getBoundKeys ( controlName )  -- get the keys bound to this control
    if not keys then                            -- make sure the control name is valid and any keys are bound to it
        outputChatBox ( "No keys bound to " .. controlName, 255, 0, 0 )
        return
    end
    outputChatBox ( "Keys bound to " .. controlName .. ":", 0, 255, 0 )
    for i,keyName in ipairs(keys) do
        outputChatBox( keyName, 0, 255, 0 )
    end
end
addCommandHandler ( "keys", keysCommand )
</syntaxhighlight>
==See Also==
{{Client input functions}}

Revision as of 08:58, 9 June 2008

Returns a list of key names that are bound to the specified game control or console command.

Syntax

table getBoundKeys ( string command/control )

Required Arguments

  • command/control: the name of a game control or a console command. See the control names page for valid controls.

Returns

If one or more keys are bound to the specified control or console command, a table is returned containing the names of all the bound keys. If no keys are bound or an invalid name was passed, returns false.

Example

This code adds a command handler with which you can check out the keybinds for any game control. As an example, typing "/keys forwards" would list all the keys which you can press to make the player walk forward.

function keysCommand ( command, controlName )
    if not controlName then                     -- make sure they specified a control name
        outputChatBox ( "No control name specified", 255, 0, 0 )
        return
    end
    local keys = getBoundKeys ( controlName )   -- get the keys bound to this control
    if not keys then                            -- make sure the control name is valid and any keys are bound to it
        outputChatBox ( "No keys bound to " .. controlName, 255, 0, 0 )
        return
    end
    outputChatBox ( "Keys bound to " .. controlName .. ":", 0, 255, 0 )
    for i,keyName in ipairs(keys) do
        outputChatBox( keyName, 0, 255, 0 )
    end
end

addCommandHandler ( "keys", keysCommand )

See Also