<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/BindControlKeys?action=history&amp;feed=atom</id>
	<title>BindControlKeys - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/BindControlKeys?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BindControlKeys&amp;action=history"/>
	<updated>2026-05-02T09:41:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BindControlKeys&amp;diff=42848&amp;oldid=prev</id>
		<title>Walman10: /* See also */</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BindControlKeys&amp;diff=42848&amp;oldid=prev"/>
		<updated>2014-11-14T13:28:10Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;See also&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:28, 14 November 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l115&quot;&gt;Line 115:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 115:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;bindControlKeys(&amp;quot;aim_weapon&amp;quot;, &amp;quot;both&amp;quot;, toggleDriveby)&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;bindControlKeys(&amp;quot;aim_weapon&amp;quot;, &amp;quot;both&amp;quot;, toggleDriveby)&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==See also==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Useful_Functions}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Useful_Functions}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-42657:rev-42848 --&gt;
&lt;/table&gt;</summary>
		<author><name>Walman10</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=BindControlKeys&amp;diff=42657&amp;oldid=prev</id>
		<title>AlexTMjugador: Created page with &quot;{{Useful Function}} &lt;lowercasetitle&gt;&lt;/lowercasetitle&gt; __NOTOC__ These useful clientside functions bind the keys bound to a control individually, using bindKey, and unbind ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=BindControlKeys&amp;diff=42657&amp;oldid=prev"/>
		<updated>2014-10-19T17:36:53Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} &amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt; __NOTOC__ These useful clientside functions bind the keys bound to a control individually, using &lt;a href=&quot;/wiki/BindKey&quot; title=&quot;BindKey&quot;&gt;bindKey&lt;/a&gt;, and unbind ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Function}}&lt;br /&gt;
&amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
These useful clientside functions bind the keys bound to a control individually, using [[bindKey]], and unbind them using [[unbindKey]]. The objective of these functions is to bypass the limitation of binding a control directly which ignores key presses if the control is deactivated at the moment (so the script would be able to react if the player presses ''aim_weapon'' in a vehicle, for example).&lt;br /&gt;
&lt;br /&gt;
==Syntaxes==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;boolean/nil bindControlKeys ( string control, misc bindData )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;boolean/nil unbindControlKeys ( string control )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
*'''control:''' The name of the control to bind or unbind. See [[control names]].&lt;br /&gt;
*'''bindData:''' (''bindControlKeys'' only) Configures how the control keys will be bound. See clientside [[bindKey]] syntaxes for reference.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
These functions return ''true'' if no error arised. They return ''nil'' plus an error message otherwise.&lt;br /&gt;
&lt;br /&gt;
==Restrictions==&lt;br /&gt;
'''You can only have one control keys bind per control'''. That should be enough for most scripts. If you want to create more binds, copy these functions into a new script file (or [[resource]]) and mark them as ''local''.&lt;br /&gt;
&lt;br /&gt;
==Functions source==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside script&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;local controls = { &amp;quot;fire&amp;quot;, &amp;quot;next_weapon&amp;quot;, &amp;quot;previous_weapon&amp;quot;, &amp;quot;forwards&amp;quot;, &amp;quot;backwards&amp;quot;, &amp;quot;left&amp;quot;, &amp;quot;right&amp;quot;, &amp;quot;zoom_in&amp;quot;, &amp;quot;zoom_out&amp;quot;,&lt;br /&gt;
 &amp;quot;change_camera&amp;quot;, &amp;quot;jump&amp;quot;, &amp;quot;sprint&amp;quot;, &amp;quot;look_behind&amp;quot;, &amp;quot;crouch&amp;quot;, &amp;quot;action&amp;quot;, &amp;quot;walk&amp;quot;, &amp;quot;aim_weapon&amp;quot;, &amp;quot;conversation_yes&amp;quot;, &amp;quot;conversation_no&amp;quot;,&lt;br /&gt;
 &amp;quot;group_control_forwards&amp;quot;, &amp;quot;group_control_back&amp;quot;, &amp;quot;enter_exit&amp;quot;, &amp;quot;vehicle_fire&amp;quot;, &amp;quot;vehicle_secondary_fire&amp;quot;, &amp;quot;vehicle_left&amp;quot;, &amp;quot;vehicle_right&amp;quot;,&lt;br /&gt;
 &amp;quot;steer_forward&amp;quot;, &amp;quot;steer_back&amp;quot;, &amp;quot;accelerate&amp;quot;, &amp;quot;brake_reverse&amp;quot;, &amp;quot;radio_next&amp;quot;, &amp;quot;radio_previous&amp;quot;, &amp;quot;radio_user_track_skip&amp;quot;, &amp;quot;horn&amp;quot;, &amp;quot;sub_mission&amp;quot;,&lt;br /&gt;
 &amp;quot;handbrake&amp;quot;, &amp;quot;vehicle_look_left&amp;quot;, &amp;quot;vehicle_look_right&amp;quot;, &amp;quot;vehicle_look_behind&amp;quot;, &amp;quot;vehicle_mouse_look&amp;quot;, &amp;quot;special_control_left&amp;quot;, &amp;quot;special_control_right&amp;quot;,&lt;br /&gt;
 &amp;quot;special_control_down&amp;quot;, &amp;quot;special_control_up&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
local boundControlsKeys = {}&lt;br /&gt;
local bindsData = {}&lt;br /&gt;
&lt;br /&gt;
function unbindControlKeys(control)&lt;br /&gt;
    -- Ensure the argument has got the appropiate type&lt;br /&gt;
    assert(type(control) == &amp;quot;string&amp;quot;, &amp;quot;Bad argument @ unbindControlKeys [string expected, got &amp;quot; .. type(control) .. &amp;quot;]&amp;quot;)&lt;br /&gt;
    -- Check if we have a valid control&lt;br /&gt;
    local validControl&lt;br /&gt;
    for _, controlComp in ipairs(controls) do&lt;br /&gt;
        if control == controlComp then&lt;br /&gt;
            validControl = true&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    assert(validControl, &amp;quot;Bad argument @ unbindControlKeys [Invalid control name]&amp;quot;)&lt;br /&gt;
    -- Have we got a bind on this control?&lt;br /&gt;
    assert(boundControlsKeys[control], &amp;quot;Bad argument @ unbindControlKeys [There is no bind on such control]&amp;quot;)&lt;br /&gt;
    -- Unbind each key of the control&lt;br /&gt;
    for _, bindData in pairs(bindsData[control]) do&lt;br /&gt;
        unbindKey(unpack(bindData))&lt;br /&gt;
    end&lt;br /&gt;
    -- Remove references&lt;br /&gt;
    boundControlsKeys[control] = nil&lt;br /&gt;
    bindsData[control] = nil&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function bindControlKeys(control, ...)&lt;br /&gt;
    -- Ensure the argument has got the appropiate type&lt;br /&gt;
    assert(type(control) == &amp;quot;string&amp;quot;, &amp;quot;Bad argument 1 @ bindControlKeys [string expected, got &amp;quot; .. type(control) .. &amp;quot;]&amp;quot;)&lt;br /&gt;
    -- Check if we have a valid control&lt;br /&gt;
    local validControl&lt;br /&gt;
    for _, controlComp in ipairs(controls) do&lt;br /&gt;
        if control == controlComp then -- Is the specified control in the table?&lt;br /&gt;
            validControl = true -- If so, it's a valid control&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    assert(validControl, &amp;quot;Bad argument 1 @ bindControlKeys [Invalid control name]&amp;quot;)&lt;br /&gt;
    -- Do we already have this control bound?&lt;br /&gt;
    if boundControlsKeys[control] then&lt;br /&gt;
        unbindControlKeys(control) -- Delete the first control keys bind&lt;br /&gt;
    end&lt;br /&gt;
    boundControlsKeys[control] = getBoundKeys(control) -- Store the keys of that control that will be bound&lt;br /&gt;
    bindsData[control] = {} -- Store bind data, so we can unbind each key of the control later&lt;br /&gt;
    for key in pairs(boundControlsKeys[control]) do&lt;br /&gt;
        -- Can we bind the key with the specified arguments?&lt;br /&gt;
        assert(bindKey(key, unpack(arg)), &amp;quot;Bad arguments @ bindControlKeys [Could not create key bind]&amp;quot;)&lt;br /&gt;
        -- If so, register the bind data and continue&lt;br /&gt;
        table.insert(bindsData[control], { key, unpack(arg) })&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- The keys bound to a control can be changed in Settings. The next function updates the binds properly in that case.&lt;br /&gt;
-- Also note that the next function IS NOT MEANT to be exported or called by the script.&lt;br /&gt;
local function keepControlKeyBindsAccurate()&lt;br /&gt;
    if next(boundControlsKeys) then -- Have we got any control keys bound?&lt;br /&gt;
        for boundControl, boundKeys in pairs(boundControlsKeys) do&lt;br /&gt;
            if toJSON(boundKeys) ~= toJSON(getBoundKeys(boundControl)) then -- Have we changed the keys bound to a control?&lt;br /&gt;
                -- Update our custom control bind&lt;br /&gt;
                for _, bindData in ipairs(bindsData[boundControl]) do&lt;br /&gt;
                    unbindKey(unpack(bindData)) -- Unbind every key of that cotnrol that we have bound before&lt;br /&gt;
                    -- Bind again the appropiate keys&lt;br /&gt;
                    for key in pairs(getBoundKeys(boundControl)) do&lt;br /&gt;
                        local bindDataNoKey = bindData -- Copy bindData into another variable&lt;br /&gt;
                        table.remove(bindDataNoKey, 1) -- Ignore the key of our bindData&lt;br /&gt;
                        bindKey(key, unpack(bindDataNoKey)) -- Bind again the data, but with the updated key&lt;br /&gt;
                        bindData[1] = key -- Update the key in the references&lt;br /&gt;
                    end&lt;br /&gt;
                end&lt;br /&gt;
                boundControlsKeys[boundControl] = getBoundKeys(boundControl) -- Update the control bound keys list&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onClientRender&amp;quot;, root, keepControlKeyBindsAccurate)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example allows players to toggle driveby by pressing or releasing the ''aim_weapon'' control.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;local function toggleDriveby()&lt;br /&gt;
    if isPedInVehicle(localPlayer) then&lt;br /&gt;
        setPedDoingGangDriveby(localPlayer, not isPedDoingGangDriveby(localPlayer))&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
bindControlKeys(&amp;quot;aim_weapon&amp;quot;, &amp;quot;both&amp;quot;, toggleDriveby)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>AlexTMjugador</name></author>
	</entry>
</feed>