API:AddBinding
From RoR Wiki
UI Lua API · Bindings functions
Version: WAR 1.4.8
Binds a key or button combination to a keyboard action.
AddBinding(action, deviceId, buttons)
Arguments
- action
string– Name of the action, as used by the key mapping window (theactionfield of its action data).- deviceId
number– Input device, one of theSystemData.InputDevicevalues (for exampleSystemData.InputDevice.KEYBOARDor.MOUSE).- buttons
number-table– Array of button IDs on that device, starting at index 1. For a keyboard combination this holds the modifier keys and the main key.
Returns
Nothing.
Details
- If
actionis not a known action, nothing happens and no error is raised. - If the action already has a binding with the same device and the same buttons in the same order, nothing happens.
- Otherwise the binding is added to the action's list of bindings. Existing bindings of the action are kept.
- A
deviceIdof0is treated as1. - Entries equal to
65535(0xFFFF) inbuttonsare skipped. - When a binding is added,
SystemData.Events.KEYBINDINGS_UPDATEDis raised. - The function needs at least three arguments and only reads the last three.
Errors
None besides the generic Invalid Parameters message when an argument has the wrong type.
Example
Replacing a binding in the key mapping window, from default/ea_keymappingwindow/source/keymappingwindow.lua:
-- Remove the old binding
if( KeyMappingWindow.actionsData[ KeyMappingWindow.SelectedActionDataIndex ]["keys"..KeyMappingWindow.bindIndex].deviceId ~= 0 )
then
local boundKeyData = KeyMappingWindow.actionsData[ KeyMappingWindow.SelectedActionDataIndex ]["keys"..KeyMappingWindow.bindIndex]
RemoveBinding( action, boundKeyData.deviceId, boundKeyData.buttons)
end
-- Add the bindings
AddBinding( action, deviceId, buttons )
