SecureActionButton with key down, mouse up - WoWInterface
Thread Tools Display Modes
05-28-21, 04:59 PM   #1
A Theradrim Guardian
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 64
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)
  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", "")
  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. ]=])

Last edited by DahkCeles : 10-10-21 at 08:42 PM. Reason: Adding more detail
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SecureActionButton with key down, mouse up

Thread Tools
Display Modes

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