Thread Tools Display Modes
02-28-16, 06:31 AM   #1
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Is it possible to do "/click" using LUA code like Macro does?

I guess my original post is a little confusing @_@ Let me make it simple.

is it possible to use LUA script to click the button I created? I'm looking for a way to do the following "Click Button_I_Created" part.

Code:
if GetMouseButtonClicked() = "RightButton"
then Click Button1_I_Created
elseif GetMouseButtonClicked() = "LeftButton"
then Click Button2_I_Created
end;
Really appreciate all the replies~


---original--------------------------------------------------------------------------------------------------------------
Hi,

Let me explain what I'd like to do. If I create a macro to "/run FuncOne()", then write the following code into a LUA file, I can use different Modifier+Mouse Click to do different actions.

Code:
FuncOne = function()
     if not IsModifierKeyDown() and GetMouseButtonClicked() ~= "RightButton"
     then DoEmote("point");
     end;
end
The reason I don't use macro directly, like [btn:1,nomod], is because macro's 255 limitation is inconvenient. So, if I create a button as follows, is it possible to click this button using the above code? I know macro can "/click" a button, how about doing it with LUA code? Thanks

Code:
local mou3 = CreateFrame("Button", "kkk", UIParent, "SecureActionButtonTemplate,ActionButtonTemplate");
mou3:SetAttribute("type1", "macro");
mou3:SetAttribute("macrotext1", "/cast spellname");
mou3:SetPoint("Center",UIParent)
mou3:RegisterForClicks("AnyUp")

Last edited by mchwxj : 02-28-16 at 07:29 PM.
  Reply With Quote
02-28-16, 06:39 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I'm not sure if macro button text can be changed in combat. There are some intersting macro addons out there though like Ifthen.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-28-16, 07:20 AM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You can't click your macro with your script, but you can hook the button's OnClick or Preclick handler to run your lua code, eg.

Lua Code:
  1. mou3:HookScript('OnClick', function(self, button, down)
  2.    if button == 'LeftButton' and not IsModifierKeyDown() then
  3.       DoEmote('point')
  4.    end
  5. end)
  Reply With Quote
02-28-16, 07:35 AM   #4
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by semlar View Post
You can't click your macro with your script, but you can hook the button's OnClick or Preclick handler to run your lua code, eg.
Thank you for the reply hum...is it possible to use LUA script to click the button I created? I'd like to do the follows. But I'm not sure if there is an approach to do the "Click Button_I_Created" part.

Code:
if GetMouseButtonClicked() = "RightButton"
then Click Button1_I_Created
elseif GetMouseButtonClicked() = "LeftButton"
then Click Button2_I_Created
end;

Last edited by mchwxj : 02-28-16 at 07:42 AM.
  Reply With Quote
02-28-16, 07:46 AM   #5
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
http://wowprogramming.com/docs/secur...ButtonTemplate
http://wowprogramming.com/docs/secur...late/attribute

lua Code:
  1. local mou3 = CreateFrame("Button", "kkk", UIParent, "SecureActionButtonTemplate,ActionButtonTemplate");
  2. mou3:SetAttribute("type1", "spell"); -- no modifier left click
  3. mou3:SetAttribute("spell1", "Rejuvenation");
  4. mou3:SetAttribute("alt-type2", "macro"); -- alt right click
  5. mou3:SetAttribute("alt-macrotext2", "/wave");
  6. mou3:SetAttribute("ctrl-type1", "macro"); -- ctrl left click
  7. mou3:SetAttribute("ctrl-macrotext1", "/bow");
  8. mou3:SetAttribute("type3", "macro"); -- no modifier middle click
  9. mou3:SetAttribute("macrotext3", "/click StanceButton1");
  10. mou3:SetPoint("Center",UIParent)
  11. mou3:RegisterForClicks("AnyUp")
  Reply With Quote
02-28-16, 01:09 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by mchwxj View Post
The reason I don't use macro directly, like [btn:1,nomod], is because macro's 255 limitation is inconvenient.
As far as I know, only user macros have the 255 character limit due to storage constraints. As such, macro text bound to a SecureActionButtonTemplate doesn't have this limit.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-28-16, 07:28 PM   #7
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Thanks for your code. Is it possible to click this button using LUA script?
  Reply With Quote
02-28-16, 07:32 PM   #8
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by zork View Post
I'm not sure if macro button text can be changed in combat. There are some intersting macro addons out there though like Ifthen.
Thanks for your recommendation Is it possible to click button using LUA script?
  Reply With Quote
02-28-16, 07:45 PM   #9
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by SDPhantom View Post
As far as I know, only user macros have the 255 character limit due to storage constraints. As such, macro text bound to a SecureActionButtonTemplate doesn't have this limit.
You're right. And I want to create a macro bound button, and click it using LUA script. Because I'd like to make it invisible.

For example, I create a macro:
Code:
/run Myfunc()
and then I write the following code in LUA
Code:
Myfunc = function()
     if GetMouseButtonClicked() = "RightButton"
     then Click Button1_I_Created
     elseif GetMouseButtonClicked() = "LeftButton"
     then Click Button2_I_Created
     end;
end;
So, everytime I click the macro, I'm actually running Myfunc(), which clicks buttons I created based on what mouse key I press. The only question is, can I click buttons using LUA code?
  Reply With Quote
02-28-16, 08:15 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://wowprogramming.com/docs/widgets/Button/Click
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-28-16, 09:40 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
The problem with this approach is using Button:Click() on a protected button can throw a protected action error.

On the other hand, I don't really get the reason why to create a button, make it invisible, then make a click-based macro to send a click event to the invisible button. Why not just make the button visible and click that directly? Either that or you can use SetBindingClick() or SetOverrideBindingClick() to set a keybind that activates the button.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-28-16 at 09:51 PM.
  Reply With Quote
02-29-16, 08:09 AM   #12
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by SDPhantom View Post
The problem with this approach is using Button:Click() on a protected button can throw a protected action error.
Thanks~ That means it can't be done, right? Then I think I'd better find another way.

Why not just make the button visible and click that directly?
Well, that's the point. because I'm just a beginner of lua coding I know how to create buttons, but I don't know how to make them work like those skill buttons do. Those buttons can be dragged everywhere and put in action bars. If you don't need them, you just drag them out of the action bar. If you need them again, you can find them on skill page.

So, I tried to use "macro button + lua script" to do that. But as you say, "Button:Click()" is unavailable on a protected button.

Last edited by mchwxj : 02-29-16 at 08:15 AM.
  Reply With Quote
02-29-16, 03:25 PM   #13
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Skill buttons being dragged around is an illusion. In fact, when you drag a button from the spellbook, it loads the spell it contains on the cursor. The game itself (not the button) renders the spell icon on the cursor until you drop it on an actionbar. At that point, the actionbar button reacts by running its OnDragReceived handler that makes the necessary changes to make it look like you dropped the spell on it.

In essence, what looks like a button being dragged from one place to another is really two buttons that never move and tricks with the cursor.



To make something a lot more simple, you only need to set the button's texture to what you want it to show using Button:SetNormalTexture().
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-29-16 at 03:31 PM.
  Reply With Quote
03-01-16, 08:10 AM   #14
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by SDPhantom View Post
Skill buttons being dragged around is an illusion. In fact, when you drag a button from the spellbook, it loads...
Thank you so much for your explanation~ It's a big help.

Trying that function I really envy you guys can write Addons as you wish.

Last edited by mchwxj : 03-01-16 at 08:21 AM.
  Reply With Quote
03-01-16, 11:55 AM   #15
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I forgot to mention, you can get rid of the ActionButtonTemplate inheritance. Keep SecureActionButtonTemplate, that's what allows you to use the attributes to run macro text securely. Just make sure you have at least one anchor and the button size set or it won't show up.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-01-16, 06:05 PM   #16
mchwxj
A Fallenroot Satyr
Join Date: Jan 2013
Posts: 20
Originally Posted by SDPhantom View Post
I forgot to mention, you can get rid of the ActionButtonTemplate inheritance. Keep SecureActionButtonTemplate, that's what allows you to use the attributes to run macro text securely. Just make sure you have at least one anchor and the button size set or it won't show up.
Got it~ Thanks

Oh, in additon, do you still have a copy of the health bar addon you attached in the following thread? I'm looking for an addon like that, and happen to review that thread just now.
If you've deleted it, that's ok, then I'm gonna look for some HUD instead
http://www.wowinterface.com/forums/s...ad.php?t=46158

Last edited by mchwxj : 03-01-16 at 07:59 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Is it possible to do "/click" using LUA code like Macro does?


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