From bf8c0aaf1a8d7fd9dc23cfdc472e4afbe469e752 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 17:12:57 -0700 Subject: [PATCH] feat: add modifier key queries and IsModifiedClick for input handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement keyboard modifier state queries using ImGui IO state: - IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown — direct key queries - IsModifiedClick(action) — checks if the modifier matching a named action is held (CHATLINK/SPLITSTACK=Shift, DRESSUP=Ctrl, SELFCAST=Alt) - GetModifiedClick(action) — returns the assigned key name for an action - SetModifiedClick — no-op stub for compatibility These are fundamental input functions used by virtually all interactive addons: shift-click to link items in chat, ctrl-click for dressup, alt-click for self-cast, shift-click to split stacks, etc. --- src/addons/lua_engine.cpp | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index ba956da9..ab5c92fe 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -4204,6 +4204,61 @@ static int lua_GetScreenHeight(lua_State* L) { return 1; } +// Modifier key state queries using ImGui IO +static int lua_IsShiftKeyDown(lua_State* L) { + lua_pushboolean(L, ImGui::GetIO().KeyShift ? 1 : 0); + return 1; +} +static int lua_IsControlKeyDown(lua_State* L) { + lua_pushboolean(L, ImGui::GetIO().KeyCtrl ? 1 : 0); + return 1; +} +static int lua_IsAltKeyDown(lua_State* L) { + lua_pushboolean(L, ImGui::GetIO().KeyAlt ? 1 : 0); + return 1; +} + +// IsModifiedClick(action) → boolean +// Checks if a modifier key combo matches a named click action. +// Common actions: "CHATLINK" (shift-click), "DRESSUP" (ctrl-click), +// "SPLITSTACK" (shift-click), "SELFCAST" (alt-click) +static int lua_IsModifiedClick(lua_State* L) { + const char* action = luaL_optstring(L, 1, ""); + std::string act(action); + for (char& c : act) c = static_cast(std::toupper(static_cast(c))); + const auto& io = ImGui::GetIO(); + bool result = false; + if (act == "CHATLINK" || act == "SPLITSTACK") + result = io.KeyShift; + else if (act == "DRESSUP" || act == "COMPAREITEMS") + result = io.KeyCtrl; + else if (act == "SELFCAST" || act == "FOCUSCAST") + result = io.KeyAlt; + else if (act == "STICKYCAMERA") + result = io.KeyCtrl; + else + result = io.KeyShift; // Default: shift for unknown actions + lua_pushboolean(L, result ? 1 : 0); + return 1; +} + +// GetModifiedClick(action) → key name ("SHIFT", "CTRL", "ALT", "NONE") +static int lua_GetModifiedClick(lua_State* L) { + const char* action = luaL_optstring(L, 1, ""); + std::string act(action); + for (char& c : act) c = static_cast(std::toupper(static_cast(c))); + if (act == "CHATLINK" || act == "SPLITSTACK") + lua_pushstring(L, "SHIFT"); + else if (act == "DRESSUP" || act == "COMPAREITEMS") + lua_pushstring(L, "CTRL"); + else if (act == "SELFCAST" || act == "FOCUSCAST") + lua_pushstring(L, "ALT"); + else + lua_pushstring(L, "SHIFT"); + return 1; +} +static int lua_SetModifiedClick(lua_State* L) { (void)L; return 0; } + // Frame methods: SetPoint, SetSize, SetWidth, SetHeight, GetWidth, GetHeight, GetCenter, SetAlpha, GetAlpha static int lua_Frame_SetPoint(lua_State* L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -4527,6 +4582,12 @@ void LuaEngine::registerCoreAPI() { {"GetPlayerFacing", lua_GetPlayerFacing}, {"GetCVar", lua_GetCVar}, {"SetCVar", lua_SetCVar}, + {"IsShiftKeyDown", lua_IsShiftKeyDown}, + {"IsControlKeyDown", lua_IsControlKeyDown}, + {"IsAltKeyDown", lua_IsAltKeyDown}, + {"IsModifiedClick", lua_IsModifiedClick}, + {"GetModifiedClick", lua_GetModifiedClick}, + {"SetModifiedClick", lua_SetModifiedClick}, {"SendChatMessage", lua_SendChatMessage}, {"SendAddonMessage", lua_SendAddonMessage}, {"RegisterAddonMessagePrefix", lua_RegisterAddonMessagePrefix},