<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AAddBinding</id>
	<title>API:AddBinding - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AAddBinding"/>
	<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:AddBinding&amp;action=history"/>
	<updated>2026-10-17T14:22:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.returnofreckoning.com/index.php?title=API:AddBinding&amp;diff=30165&amp;oldid=prev</id>
		<title>Maintenance script: UI Lua API import (WAR 1.4.8)</title>
		<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:AddBinding&amp;diff=30165&amp;oldid=prev"/>
		<updated>2026-10-16T19:40:16Z</updated>

		<summary type="html">&lt;p&gt;UI Lua API import (WAR 1.4.8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{LuaApi|group=Bindings}}&lt;br /&gt;
Binds a key or button combination to a keyboard action.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
AddBinding(action, deviceId, buttons)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments ==&lt;br /&gt;
;action : &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; – Name of the action, as used by the key mapping window (the &amp;lt;code&amp;gt;action&amp;lt;/code&amp;gt; field of its action data).&lt;br /&gt;
;deviceId : &amp;lt;code&amp;gt;number&amp;lt;/code&amp;gt; – Input device, one of the &amp;lt;code&amp;gt;SystemData.InputDevice&amp;lt;/code&amp;gt; values (for example &amp;lt;code&amp;gt;SystemData.InputDevice.KEYBOARD&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;.MOUSE&amp;lt;/code&amp;gt;).&lt;br /&gt;
;buttons : &amp;lt;code&amp;gt;number-table&amp;lt;/code&amp;gt; – Array of button IDs on that device, starting at index 1. For a keyboard combination this holds the modifier keys and the main key.&lt;br /&gt;
&lt;br /&gt;
== Returns ==&lt;br /&gt;
Nothing.&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
* If &amp;lt;code&amp;gt;action&amp;lt;/code&amp;gt; is not a known action, nothing happens and no error is raised.&lt;br /&gt;
* If the action already has a binding with the same device and the same buttons in the same order, nothing happens.&lt;br /&gt;
* Otherwise the binding is added to the action&amp;#039;s list of bindings. Existing bindings of the action are kept.&lt;br /&gt;
* A &amp;lt;code&amp;gt;deviceId&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; is treated as &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Entries equal to &amp;lt;code&amp;gt;65535&amp;lt;/code&amp;gt; (0xFFFF) in &amp;lt;code&amp;gt;buttons&amp;lt;/code&amp;gt; are skipped.&lt;br /&gt;
* When a binding is added, &amp;lt;code&amp;gt;SystemData.Events.KEYBINDINGS_UPDATED&amp;lt;/code&amp;gt; is raised.&lt;br /&gt;
* The function needs at least three arguments and only reads the last three.&lt;br /&gt;
&lt;br /&gt;
== Errors ==&lt;br /&gt;
None besides the generic &amp;#039;&amp;#039;Invalid Parameters&amp;#039;&amp;#039; message when an argument has the wrong type.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Replacing a binding in the key mapping window, from &amp;lt;code&amp;gt;default/ea_keymappingwindow/source/keymappingwindow.lua&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Remove the old binding&lt;br /&gt;
if( KeyMappingWindow.actionsData[ KeyMappingWindow.SelectedActionDataIndex ][&amp;quot;keys&amp;quot;..KeyMappingWindow.bindIndex].deviceId ~= 0 )&lt;br /&gt;
then&lt;br /&gt;
    local boundKeyData = KeyMappingWindow.actionsData[ KeyMappingWindow.SelectedActionDataIndex ][&amp;quot;keys&amp;quot;..KeyMappingWindow.bindIndex]&lt;br /&gt;
    RemoveBinding( action, boundKeyData.deviceId, boundKeyData.buttons)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Add the bindings&lt;br /&gt;
AddBinding( action, deviceId, buttons )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[API:RemoveBinding|RemoveBinding]]&lt;br /&gt;
* [[API:RemoveAllBindings|RemoveAllBindings]]&lt;br /&gt;
* [[API:RestoreDefaultBindings|RestoreDefaultBindings]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>