Skip to content

Return of Reckoning

Wiki

RoR Wiki

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 (the action field of its action data).
deviceId
number – Input device, one of the SystemData.InputDevice values (for example SystemData.InputDevice.KEYBOARD or .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 action is 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 deviceId of 0 is treated as 1.
  • Entries equal to 65535 (0xFFFF) in buttons are skipped.
  • When a binding is added, SystemData.Events.KEYBINDINGS_UPDATED is 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 )

See also