I think you could try something along these lines
Code:
local button = CreateFrame(
"Button", "NameThisButton", nil, "SecureActionButtonTemplate"
)
button:SetAttribute("type", "macro")
button:SetAttribute("macrotext", "/cast [@cursor] Death and Decay")
and then
Code:
SetBindingClick("ALT-BUTTON1", "NameThisButton")
As for your second question, you can listen to all key presses like this, but you can't run any protected code in the handler.
Code:
local MODS = {
SHIFT = IsShiftKeyDown,
ALT = IsAltKeyDown,
CTRL = IsControlKeyDown,
}
local MODS_SEPARATE = {
LSHIFT = IsLeftShiftKeyDown,
LALT = IsLeftAltKeyDown,
LCTRL = IsLeftControlKeyDown,
RSHIFT = IsRightShiftKeyDown,
RALT = IsRightAltKeyDown,
RCTRL = IsRightControlKeyDown,
}
local frame = CreateFrame("Frame", nil, UIParent)
frame:EnableKeyboard(true)
frame:SetPropagateKeyboardInput(true)
frame:SetFrameStrata("DIALOG")
local function getMods(checks)
local mods = ""
for mod, isDown in pairs(checks) do
if isDown() then
mods = mods .. mod .. "-"
end
end
return mods
end
frame:SetScript("OnKeyDown", function (_self, key)
if MODS[key] or MODS_SEPARATE[key] then
return
end
print(getMods(MODS_SEPARATE) .. key)
end)
Note that you could also listen for MODIFIER_STATE_CHANGED and cache the states. However, alt-tabbing can mess this up as the event will only fire for one state but not the other.