Thread Tools Display Modes
04-03-23, 01:20 AM   #1
jeroenvo
A Murloc Raider
Join Date: Apr 2023
Posts: 4
Cant get a button click to execute a macro

Hello!

Im new to wow lua scripting and trying to make a addon that executes a macro text on a button click. When i bind a macrotext to a button (/sit as a example) nothing happens when i click it.

I found this example somewhere online:

Code:
local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
frame:SetSize(40, 40)
frame:SetPoint("TOPLEFT", UIParent, 10, -150)
 
local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
button:ClearAllPoints()
button:SetSize(32, 32)
button:SetPoint("CENTER", frame)

local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
texture:SetAllPoints(true)
texture:SetTexture(GetSpellTexture(783))
button.texture = texture
 
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:SetMouseClickEnabled(true)
button:SetAttribute("type1", "macro")
button:SetAttribute("macrotext", "/sit")
 
button:SetScript("PostClick", function(self, arg1)
    print("POSTCLICK: Clicked button=", self:GetName(), "  macroTxt=", self:GetAttribute("macrotext"))
end)
The PostClick function gets called but the /sit is not being executed. Does someone knows what the issue is?
  Reply With Quote
04-03-23, 11:32 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
It should be executing /sit on leftbutton, but not rightbutton

Lua Code:
  1. local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
  2. frame:SetSize(40, 40)
  3. frame:SetPoint("TOPLEFT", UIParent, 10, -150)
  4.  
  5. local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
  6. button:ClearAllPoints()
  7. button:SetSize(32, 32)
  8. button:SetPoint("CENTER", frame)
  9.  
  10. local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
  11. texture:SetAllPoints(true)
  12. texture:SetTexture(GetSpellTexture(783))
  13. button.texture = texture
  14.  
  15. button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  16. button:SetAttribute("type1", "macro")
  17. button:SetAttribute("type2", "macro")
  18. button:SetAttribute("macrotext", "/sit")
  19.  
  20. button:SetScript("PostClick", function(self, arg1)
  21.     print("POSTCLICK: Clicked button=", self:GetName(), arg1, "  macroTxt=", self:GetAttribute("macrotext"))
  22. end)

Added
Code:
button:SetAttribute("type2", "macro")
for rightbutton.

For information on click attributes (Modified attributes) see
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-03-23 at 11:44 AM.
  Reply With Quote
04-03-23, 01:08 PM   #3
jeroenvo
A Murloc Raider
Join Date: Apr 2023
Posts: 4
Thanks for your reply! The macro is still not being executed. Also tried to disable all my other addons.
  Reply With Quote
04-03-23, 01:29 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
You probably have the ActionButtonUseKeyDown CVar set to 1.

Register the button to use Down clicks instead of Up or,

run
Code:
/console ActionButtonUseKeyDown 0
and try again.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-03-23 at 05:20 PM.
  Reply With Quote
04-04-23, 12:56 AM   #5
jeroenvo
A Murloc Raider
Join Date: Apr 2023
Posts: 4
Originally Posted by Fizzlemizz View Post
You probably have the ActionButtonUseKeyDown CVar set to 1.

Register the button to use Down clicks instead of Up or,

run
Code:
/console ActionButtonUseKeyDown 0
and try again.
The command didn't work. The PostClick function is called. It prints the string in chat but the macro is not executed
  Reply With Quote
04-04-23, 09:08 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
The code as posted (with the CVar in sync. with the registered clicks) works here on retail.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-05-23, 04:00 AM   #7
jeroenvo
A Murloc Raider
Join Date: Apr 2023
Posts: 4
Added SetCVar("ActionButtonUseKeyDown", 0) as first line of the script and now it works. Thanks for your help!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Cant get a button click to execute a macro


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