How to add buttons to the keybind strip

From ESOUI Wiki

Jump to: navigation, search

When you're inside a UI element and you see that black section at the bottom of the screen, with useful functions and the keys you press to enact them, that is the keybind strip. This tutorial shows you how to add your own button to that strip.


First, know the keybinding name for the thing you want to do. You can use one of ESO's pre-defined keybindings. You can also create your own keybindings.


The keybind strip has two sections: "center" and "right". The convention is that the "right" section is reserved for the exit key, and the "center" section is for the action keys.


Keybind buttons are added to the keybind strip in groups. A group can consist of one or more buttons.


Contents

Adding Keybind Buttons

The first step is to prepare your keybind button or button groups. You can have one button within its own group:


myButtonGroup = {
	{
		name = "Do Something",
		keybind = "UI_SHORTCUT_PRIMARY",
		callback = function() MyDoSomething() end,
	},
	alignment = KEYBIND_STRIP_ALIGN_CENTER,
}


You can have more than one button in a group:

myButtonGroup = {
	{
		name = "Do Something",
		keybind = "UI_SHORTCUT_PRIMARY",
		callback = function() MyDoSomething() end,
	},
	{
		name = "Do Something Else",
		keybind = "UI_SHORTCUT_SECONDARY",
		callback = function() MyDoSomethingElse() end,
	},
	alignment = KEYBIND_STRIP_ALIGN_CENTER,
}

Either way, once you are ready to add your button(s) to the keybind strip (say, when your UI window is opened), do the following:

KEYBIND_STRIP:AddKeybindButtonGroup(myButtonGroup)

Now, every time the button attached to your keybind is pressed, the associated callback function runs. In this example, if you press the UI_SHORTCUT_PRIMARY key (default is E), the function MyDoSomething() will run. If you press the UI_SHORTCUT_SECONDARY key (default is R), the function MyDoSomethingElse() will run.

Removing Your Keybind Buttons

When you are ready to remove your button(s) from the keybind strip (say, when your UI window is closed), do the following:

KEYBIND_STRIP:RemoveKeybindButtonGroup(myButtonGroup)

Manipulating Your Keybind Buttons

General

You can access your buttons once they're on the keybind strip through the variable KEYBIND_STRIP.keybinds . KEYBIND_STRIP.keybinds.UI_SHORTCUT_PRIMARY will give the "Do Something" button UI element in our example.

Show/Hide, Enable/Disable

You can show or hide keybind strip buttons based on your UI window's state, as well. You will need to add an optional entry in the button descriptor:

myButtonGroup = {
	{
		name = "DoSomething",
		keybind = "UI_SHORTCUT_PRIMARY",
		callback = function() MyDoSomething() end,
		visible = function() ShouldIBeShowing() end,
	},
	alignment = KEYBIND_STRIP_ALIGN_CENTER,
}

Here, the function ShouldIBeShowing() returns true if the button should be showing when the function is run, and false if it shouldn't.

To trigger the "visible" function and make the keybind strip comply with it, run this function every time you want the keybind strip to update:

KEYBIND_STRIP:UpdateKeybindButtonGroup(myButtonGroup)

If you want your button to be visible but sometimes grayed out (non-functional), you can use the optional entry "enabled" in the button descriptor. This entry works the same way the "visible" entry does.

Shortcut for a Simple, Single Keybind Button

If you are only adding one button to the keybind strip, and you want it to be in its own group, there is a shortcut function that will serve you. To use it, you need to define your button descriptor a little differently:

myButton = {
	name = "Do Something",
	keybind = "UI_SHORTCUT_PRIMARY",
	callback = function() MyDoSomething() end,
	alignment = KEYBIND_STRIP_ALIGN_CENTER,
}

Then you can add it and remove it like this:

KEYBIND_STRIP:AddKeybindButton(myButton)
KEYBIND_STRIP:RemoveKeybindButton(myButton)

Otherwise, your button will behave exactly like any other described above.

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox