Macro using mouse buttons to execute slash commands

I use this macro for my rogue poisons:

#showtooltip Instant Poison
/use [button:1] Instant Poison
/use [button:2] Crippling Poison

and was trying to do something similar for two slash commands in an addon:

/use [button:1] /MyAddon showFrame
/use [button:2] /MyAddon hideFrame

which doesn’t work

After looking at several forums I found this:

/run r=SecureCmdOptionParse(“[button:1]/MyAddon showFrame;/MyAddon hideFrame”) DEFAULT_CHAT_FRAME.editBox:SetText(r) ChatEdit_SendText(DEFAULT_CHAT_FRAME.editBox, 0)

Will this violate the TOS? Seems like it could be abused.

Should be fine, it’s still 1 action per hardware event.

You could just make a toggle command in the addon itself that checks if the frame is hidden/visible the runs the appropriate sub command.

Elvenbane, thanks for the comment. My bad for using a poor example. I am actually using this to toggle the frame and if the mouse button is pushed to store some data in a database. But good catch in case anyone else needs something similar.

1 Like

You could also simplify ur life and use Macro-Talk
https://www.curseforge.com/wow/addons/macro-talk

Then your macro would just be:

/opt [btn:1] /MyAddon showFrame; /MyAddon hideFrame

It’s unclear from this what you are actually doing. Trying to mimic an addon’s slash command in a macro or trying to create a slash command in an addon you are writing?

As Elvenbane said, clicking a macro button or typing a slash command and pressing enter are equivelent actions.

If you are trying to add slash commands to your addon though then that is something different

1 Like

And this sounds like you have an addon but want to add a button to toggle showing/hiding a frame and maybe do other things? Which is something different again.

1 Like

I apologize for all the confusion. I have a completed addon that has multiple slash commands. One of the slash commands toggles showing/hiding the frame. Another of the commands, fills a database with a bunch of information(player info, # of herbs/ore etc., timedate’s for reminders…and so on). This addon saves all the data under a per character saved variable. Outside the game, a C# app parses the saved data files and displays it in a form.

The code in your slash command(s) can be moved into functions of their own eg.

local function ToggleAddonFrame()
    MyAddo0nFrame:SetShown(not MyAddo0nFrame:IsShown())
end

local function SaveSomeData()
    MySavedVariableTable.SomeKey = "YadaYadaYada"
end

Your slash commmands can use the functions eg.

SlashCmdList.MySlashCode = function(msg)
    if strupper(msg) == "TOGGLE" then
        ToggleAddonFrame()
    elseif strupper(msg) == "SAVE" then
        SaveSomeData()
    end
end

And you can add a button using it’s OnClick script to do whatever you want

local f = CreateFrame("Button", "MyAddonToggleButton", UIParent, "UIPanelButtonTemplate")
f:SetSize(80, 25)
f:SetText("Toggle")
f:SetPoint("TOP", 0, -10) -- position the button top center of the screen
f:RegisterForClicks("LeftButtonUp", "RightButtonUp")
f:SetScript("OnClick", function(self, button)
    if button == "LeftButton" then
        ToggleAddonFrame()
    else
        SaveSomeData()
    end
end)

The function(s) will have to be above the button and slash command in your code file.