Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
mNo edit summary
No edit summary
Tag: WoW API docs
 
(17 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
{{wowapi}}
 
{{wowapi}}
  +
Returns the name and keys for a binding by index.
Returns the command name and all keys currently bound to the command specified by ''index''. This would generally be used in conjunction with [[API GetNumBindings|GetNumBindings()]] to loop through and set/get all of the key bindings available.
 
 
command, category, key1, key2, ... = GetBinding(index [, alwaysIncludeGamepad])
   
 
==Arguments==
----
 
 
:;index:{{apitype|number}} - index of the binding to query, from 1 to [[API GetNumBindings|GetNumBindings]]().
;''Arguments''
 
  +
:;alwaysIncludeGamepad:{{apitype|boolean?}} - If gamepad support is disabled, then gamepad bindings are only returned if this is <code>true</code>.
   
 
==Returns==
:(Int index)
 
  +
:;command:{{apitype|string}} - Command this binding will perform (e.g. MOVEFORWARD). For well-behaved bindings, a human-readable description is stored in the <code>_G["BINDING_NAME_" .. command]</code> global variable.
  +
:;category:{{apitype|string}} - Category this binding was declared in (e.g. BINDING_HEADER_MOVEMENT). For well-behaved bindings, a human-readable title is stored in the <code>_G[category]</code> global variable.
  +
:;key1, key2, ...:{{apitype|string?}} - Key combination this binding is bound to (e.g. W, CTRL-F). <code>key1</code> and <code>key2</code> can be nil if there is nothing bound to the command.
   
  +
==Details==
:;index : A value from 1 to X where X is the number returned from [[API GetNumBindings|GetNumBindings()]]
 
  +
* Even though the default Key Binding window only shows up to two bindings for each command, it is actually possible to bind more using [[API SetBinding|SetBinding]], and this function will return all of the keys bound to the given command, not just the first two.
   
 
==Example==
----
 
  +
<syntaxhighlight lang="lua">
;''Returns''
 
  +
local function dumpBinding(command, category, ...)
  +
local cmdName = _G["BINDING_NAME_" .. command]
  +
local catName = _G[category]
  +
print(("%s > %s (%s) is bound to:"):format(catName or "?", cmdName or "?", command), strjoin(", ", ...))
  +
end
   
  +
dumpBinding(GetBinding(5)) -- "Movement Keys > Turn Right (TURNRIGHT) is bound to: D, RIGHT"
:command, key1, key2, ..., keyN
 
  +
</syntaxhighlight>
   
  +
==See also==
:;command : (string) The name of the command the keys are bound to (e.g. MOVEFORWARD, TOGGLEFRIENDSTAB). Used in [[API GetBindingKey|GetBindingKey("command")]] among other things.
 
  +
* [[API GetBindingAction|GetBindingAction]]
:;key1-N : (string) The string representation of the key bound to this command (e.g. W, CTRL-F). Even though the default key binding GUI window only displays 2 possible keys bound to each command, it appears there is no limit to the number of keys that can be bound to a single command. This function will return as many keys as have been set with [[API SetBinding|SetBinding("key"{,"command"})]].
 
  +
* [[API GetBindingKey|GetBindingKey]]
 
  +
* [[API GetBindingByKey|GetBindingByKey]]
----
 
  +
* [[Bindings.xml]]
;''Example''
 
  +
<!-- emmylua
command, key1, key2 = GetBinding(5);
 
  +
---@param index number
DEFAULT_CHAT_FRAME:AddMessage(command.." has the following keys bound:",1.0,1.0,1.0);
 
  +
---@param alwaysIncludeGamepad? boolean
if (key1) then DEFAULT_CHAT_FRAME:AddMessage(key1,1.0,1.0,1.0); end
 
  +
---@return string command
if (key2) then DEFAULT_CHAT_FRAME:AddMessage(key2,1.0,1.0,1.0); end
 
  +
---@return string category
  +
---@return string? key1
  +
---@return string? key2
  +
---@return string? ...
  +
function GetBinding(index, alwaysIncludeGamepad) end
 
-->

Latest revision as of 22:56, 19 September 2023

Returns the name and keys for a binding by index.

command, category, key1, key2, ... = GetBinding(index [, alwaysIncludeGamepad])

Arguments

index
number - index of the binding to query, from 1 to GetNumBindings().
alwaysIncludeGamepad
boolean? - If gamepad support is disabled, then gamepad bindings are only returned if this is true.

Returns

command
string - Command this binding will perform (e.g. MOVEFORWARD). For well-behaved bindings, a human-readable description is stored in the _G["BINDING_NAME_" .. command] global variable.
category
string - Category this binding was declared in (e.g. BINDING_HEADER_MOVEMENT). For well-behaved bindings, a human-readable title is stored in the _G[category] global variable.
key1, key2, ...
string? - Key combination this binding is bound to (e.g. W, CTRL-F). key1 and key2 can be nil if there is nothing bound to the command.

Details

  • Even though the default Key Binding window only shows up to two bindings for each command, it is actually possible to bind more using SetBinding, and this function will return all of the keys bound to the given command, not just the first two.

Example

local function dumpBinding(command, category, ...)
	local cmdName = _G["BINDING_NAME_" .. command]
	local catName = _G[category]
	print(("%s > %s (%s) is bound to:"):format(catName or "?", cmdName or "?", command), strjoin(", ", ...))
end

dumpBinding(GetBinding(5)) -- "Movement Keys > Turn Right (TURNRIGHT) is bound to: D, RIGHT"

See also