Thread Tools Display Modes
10/25/22, 04:24 PM   #1
PrimeRibeye
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 2
Adding a Keybind for My Addon

Hey guys, I'm looking to add a keybind for my addon instead of people having to type a /command in chat. Any help will be possible.



It's just a simple add on I have that allows people to port to my house by typing /crafting in text chat. I'd like to add a hotkey option where they can hotkey and have the ability to jump pressing 1 button.

Link to Addon: https://www.esoui.com/downloads/info...tingHouse.html
  Reply With Quote
10/25/22, 10:43 PM   #2
wookiefriseur
 
wookiefriseur's Avatar
Join Date: Mar 2014
Posts: 53
Talking Or just use Housing Hub

Some useful links in https://www.esoui.com/forums/showthread.php?t=9867


You could probably do something like that:


Bindings.xml

Xml Code:
  1. <Bindings>
  2.     <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.         <Category name="PrimeRibeye's AddOn">
  4.             <Action name="Travel to Crafting House">
  5.                 <Down>CraftingHouse.Port()</Down>
  6.             </Action>
  7.         </Category>
  8.     </Layer>
  9. </Bindings>


Don't forget to make the local Port function available globally, for instance with
Lua Code:
  1. CraftingHouse.Port = Port()
, and to add the Bindings.xml to your CraftingHouse.txt
That should be enough, but can't test it ingame right now.
  Reply With Quote
10/26/22, 01:36 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,964
Edit:
As this is related to addon coding I've moved the thread to the lua/XML forum.



A good start is the ESOUI WIKI, to find examples, tutorials and code snippets, or the threads that Wookiefriseur linked above (it contains the info about the WIKI too).
https://wiki.esoui.com/Main_Page

Just search for keybind there andyou will find some tutorials using keybinds in their addons:
https://wiki.esoui.com/w/index.php?t...=keybind&go=Go

https://wiki.esoui.com/Keybindings
https://wiki.esoui.com/How_to_add_bu..._keybind_strip
  Reply With Quote
10/27/22, 04:41 PM   #4
PrimeRibeye
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 2
Originally Posted by wookiefriseur View Post
Some useful links in https://www.esoui.com/forums/showthread.php?t=9867


You could probably do something like that:


Bindings.xml

Xml Code:
  1. <Bindings>
  2.     <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.         <Category name="PrimeRibeye's AddOn">
  4.             <Action name="Travel to Crafting House">
  5.                 <Down>CraftingHouse.Port()</Down>
  6.             </Action>
  7.         </Category>
  8.     </Layer>
  9. </Bindings>


Don't forget to make the local Port function available globally, for instance with
Lua Code:
  1. CraftingHouse.Port = Port()
, and to add the Bindings.xml to your CraftingHouse.txt
That should be enough, but can't test it ingame right now.


XML
<Bindings>
<Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
<Category name="Crafting House">
<Action name="Port to Craftinghouse">
<Down>CraftingHouse.Port()</Down>
</Action>
</Category>
</Layer>
</Bindings>

LUA
CraftingHouse = {}
CraftingHouse.name = "CraftingHouse"
------------------------
function CraftingHouse.Port()

d("Porting to the crafting house.")
JumpToSpecificHouse("@lIIIlIIIl", 47)
end

function CraftingHouse.OnAddOnLoaded(event, addonName)
if addonName == CraftingHouse.name then
SLASH_COMMANDS["/crafting"] = CraftingHouse.Port


EVENT_MANAGER:UnregisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED)
end
end

EVENT_MANAGER:RegisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED, CraftingHouse.OnAddOnLoaded)
I did everything exactly right but I can't get it to show up under keybinds in game.
  Reply With Quote
10/27/22, 06:59 PM   #5
wookiefriseur
 
wookiefriseur's Avatar
Join Date: Mar 2014
Posts: 53
Oh, yeah..looks like the Binding.xml expects a variable to generate the string, instead of writing the text directly into it.


CraftingHouse.lua
Lua Code:
  1. -- *** CraftingHouse ***
  2.  
  3. CraftingHouse = {}
  4. CraftingHouse.name = "CraftingHouse"
  5. ------------------------
  6. function CraftingHouse.Port()
  7.  
  8.    d("Porting to the crafting house.")
  9.    JumpToSpecificHouse("@lIIIlIIIl", 47)
  10. end
  11.  
  12. function CraftingHouse.OnAddOnLoaded(event, addonName)
  13.   if addonName == CraftingHouse.name then
  14.     SLASH_COMMANDS["/crafting"] = CraftingHouse.Port
  15.    
  16.     EVENT_MANAGER:UnregisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED)
  17.   end
  18. end
  19.  
  20. ZO_CreateStringId("SI_BINDING_NAME_CRAFTINGHOUSE_PORT", "Travel to Crafting House")
  21. EVENT_MANAGER:RegisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED, CraftingHouse.OnAddOnLoaded)


Bindings.xml
Xml Code:
  1. <Bindings>
  2.    <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.      <Category name="PrimeRibeye's AddOn">
  4.        <Action name="CRAFTINGHOUSE_PORT">
  5.          <Down>CraftingHouse.Port()</Down>
  6.       </Action>
  7.     </Category>
  8.   </Layer>
  9. </Bindings>




CraftingHouse.txt
Code:
## Title: | CraftingHouse |r
## Description: Use "/crafting" to port to the crafting house
## Author: |PrimeRibeye|r
## Version: 2.7
## APIVersion: 101034 101035
## SavedVariables:
## DependsOn:

##AddOnVersion: 2
##IsLibrary: false

CraftingHouse.lua
Bindings.xml

# This Addon is not created by, affiliated with, or sponsored by
# ZeniMax Media Inc. or its affiliates
# The Elder Scrolls (c) and related logos are registered trademarks
# or trademarks of ZeniMax Media Inc. in the United States and/or
# other countries.  All rights reserved
  Reply With Quote
10/28/22, 05:22 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,964
Originally Posted by wookiefriseur View Post
Oh, yeah..looks like the Binding.xml expects a variable to generate the string, instead of writing the text directly into it.
Yep, ESO forces you to use Multi language support here, which is the correct way imo ;-)

https://wiki.esoui.com/Key_bindings
Code:
<Bindings>
   <Layer name="SI_MY_ADDON_LAYER">
      <Category name="SI_MAIN_FUNCTIONS">
         <Action name="TURN_RIGHT">
            <Down>TurnRightStart()</Down>
            <Up>TurnRightStop()</Up>
         </Action>
      </Category>
   </Layer>
</Bindings>
Layers and categories use the same names internally and on the UI; the game will pass the names through GetString to display them. Actions will have the string SI_BINDING_NAME_ prepended to their names, and the results will be passed through GetString for display (i.e. our example above would be GetString(SI_BINDING_NAME_TURN_RIGHT) which needs to be defined in your addon as string constant
https://wiki.esoui.com/How_to_add_lo...eating_strings
).

Last edited by Baertram : 10/28/22 at 05:25 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Adding a Keybind for My Addon


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off