From 0ef4fe1818ac7d038a8fdc4c922289761099eba3 Mon Sep 17 00:00:00 2001 From: Artur Morozov Date: Wed, 9 Sep 2026 10:51:51 +0300 Subject: [PATCH] add support for 'button' conditional (#3) * add support for 'button' conditional * Route [button] through Multi, add [nobutton], register as static - [button] now reads conditionals.button via Multi(...) instead of indexing _groups.button[1].values[1] directly, so OR/AND lists and repeated groups behave like every other argument conditional. [button:1/2] now matches left or right; previously only the first value was ever checked and the rest were silently dropped. This also removes the unguarded _groups reach-in, which Multi itself defends against (it checks _groups is present and falls back to _operators). - Adds [nobutton:N] via NegatedMulti, following the convention that every conditional ships its negation (nomod, nostance, nokeydown, ...). - Bare [button] / [nobutton] now mean "any / no mapped mouse button held", mirroring bare [mod]. Bare [nobutton] doubles as an "activated by a keybind rather than a click" test. - Registers button/nobutton in STATIC_CONDITIONALS next to mod and keydown, so they are checked once up front rather than re-evaluated for every candidate unit during multiscan target scanning. Still open: IsMouseButtonDown reports live physical state, so a keybound macro has no button held and [button:N] is false for it, and whether the button still reads down at macro-execution time depends on whether the action button fires on mouse-down or mouse-up. Needs in-game verification. --------- Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com> --- Conditionals.lua | 25 +++++++++++++++++++++++++ Utility.lua | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Conditionals.lua b/Conditionals.lua index 0c9cafe..6eb2ae7 100644 --- a/Conditionals.lua +++ b/Conditionals.lua @@ -5422,6 +5422,30 @@ end -- A list of Conditionals and their functions to validate them CleveRoids.Keywords = { + -- [button:N] — true while mouse button N is held (1=Left, 2=Right, 3=Middle, + -- 4/5=extra). Routed through Multi so OR/AND lists and repeated groups behave + -- like every other argument conditional ([button:1/2] = left or right). + -- [button] with no argument — true if any mapped mouse button is held. + button = function(conditionals) + if type(conditionals.button) ~= "table" then + return CleveRoids.AnyMouseButtonDown() + end + return Multi(conditionals.button, function(button) + local name = CleveRoids.buttons[button] + return name and IsMouseButtonDown(name) or false + end, conditionals, "button") + end, + + nobutton = function(conditionals) + if type(conditionals.nobutton) ~= "table" then + return not CleveRoids.AnyMouseButtonDown() + end + return NegatedMulti(conditionals.nobutton, function(button) + local name = CleveRoids.buttons[button] + return not (name and IsMouseButtonDown(name)) + end, conditionals, "nobutton") + end, + exists = function(conditionals) return UnitExists(conditionals.target) end, @@ -9330,6 +9354,7 @@ CleveRoids.STATIC_CONDITIONALS = { inbag = true, noinbag = true, mod = true, nomod = true, keydown = true, nokeydown = true, + button = true, nobutton = true, swimming = true, noswimming = true, swim = true, noswim = true, indoors = true, noindoors = true, outdoors = true, nooutdoors = true, rooted = true, norooted = true, diff --git a/Utility.lua b/Utility.lua index 336a5f7..c76a4e1 100644 --- a/Utility.lua +++ b/Utility.lua @@ -656,6 +656,24 @@ function CleveRoids.PrintT(t, depth) end end +CleveRoids.buttons = { + ['1'] = 'LeftButton', + ['2'] = 'RightButton', + ['3'] = 'MiddleButton', + ['4'] = 'Button4', + ['5'] = 'Button5', +} + +-- True while any mapped mouse button is held. Backs the argument-less [button] / +-- [nobutton], mirroring how a bare [mod] means "any modifier". Bare [nobutton] is +-- the practical "activated by a keybind, not a click" test. +function CleveRoids.AnyMouseButtonDown() + for _, name in pairs(CleveRoids.buttons) do + if IsMouseButtonDown(name) then return true end + end + return false +end + CleveRoids.kmods = { ctrl = IsControlKeyDown, lctrl = IsLeftControlKeyDown,