Quantcast Binding a spell @cursor - WoWInterface
Thread Tools Display Modes
05-11-19, 03:24 AM   #1
doofus
A Black Drake
Join Date: Feb 2018
Posts: 84
Binding a spell @cursor

I would like to do "alt click" and it to drop D&D where the cursor is, no questions asked. I can do "SetBindings("ALT-BUTTON1", "SPELL Death and Decay") but it's missing the "@cursor". The way around it I can see is to do "SetBindings("ALT-BUTTON1", "MACRO DeathAndDecay")" where the macro does "/cast [@cursor] Death and Decay".

Is there a better way of doing this so that I can skip the macro?

IN ADDITION:

I have a number of key bindings to macros where my addon code sets up the key bindings in LUA, this ties a key press to a macro, and the macro calls back the addon via the /command system. A bit of round about way. Can I instead bind a key to execute some LUA code directly and to avoid having to set up macros which are stored and maintained externally to my addon ?

Last edited by doofus : 05-11-19 at 03:29 AM.
  Reply With Quote
05-14-19, 11:51 AM   #2
veyh
A Kobold Labourer
Join Date: Jul 2016
Posts: 1
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.

Last edited by veyh : 05-14-19 at 12:35 PM.
  Reply With Quote
05-17-19, 12:10 PM   #3
doofus
A Black Drake
Join Date: Feb 2018
Posts: 84
OK thanks. The first example allows me to set up a macro from the addon, without using the WoW client. This is good, if it means I do not have to litter the WoW client with macros.

The second example, I believe, allows me to listen to keystrokes but I am not sure why I would want to listen to raw keystrokes - maybe this allows me to run ANY code at all without even using a macro attached to a button ?
  Reply With Quote
05-17-19, 04:26 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,769
The second example is how to have an addon run its own code when a key is pressed. It won't let you do protected actions like use an ability. You have to still mess around with the keybind system and SecureActionButton templates.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
Today, 04:08 AM   #5
doofus
A Black Drake
Join Date: Feb 2018
Posts: 84
Thank you. I have not had time to analyse the second part yet, as I am still trying to find my way around the best way to do what I want to do.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Binding a spell @cursor

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