WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SecureActionButton with key down, mouse up (https://www.wowinterface.com/forums/showthread.php?t=58768)

DahkCeles 05-28-21 04:59 PM

SecureActionButton with key down, mouse up
 
Here is a way to securely mimic the console variable ActionButtonUseKeyDown, so that custom action bars (beyond the default UI range) can respond during combat to key-press (down) and mouse-release (up).

This workaround starts by setting the keybind to something obscure like Button31, and using SetAttribute("Button31", "") so that the keybind basically does nothing. Then, a secure wrapper (made possible via SecureHandlerBaseTemplate) will check if it is a down stroke and convert it to LeftButton so that the action can trigger as if it were a mouse click.

(Mimicking LeftButton also allows users to write [btn:1] in macros and have it fire via the obscure keybinding.)


Lua Code:
  1. -- create a typical action button... but also inherit SecureHandlerBaseTemplate
  2. local button = CreateFrame("CheckButton", "myActionButton80", nil, "SecureActionButtonTemplate,SecureHandlerBaseTemplate")
  3. button:SetAttribute("type", "action")
  4. button:SetAttribute("action", 80)
  5.  
  6. -- give it an obscure keybinding, and register it to do nothing
  7. SetBinding("SHIFT-Q", "CLICK myActionButton80:Button31")
  8. button:RegisterForClicks("AnyUp", "Button31Down")
  9. button:SetAttribute("type31", "")
  10.  
  11. -- Here is the magic to convert a key-down into LeftButton
  12. button:WrapScript(button, "OnClick", [=[
  13.     -- self, button, down
  14.     if (button == "Button31" and down) then
  15.         return "LeftButton"
  16.     end
  17. ]=])


All times are GMT -6. The time now is 12:19 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI