WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Binding a spell @cursor (https://www.wowinterface.com/forums/showthread.php?t=57138)

doofus 05-11-19 03:24 AM

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 ?

veyh 05-14-19 11:51 AM

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.

doofus 05-17-19 12:10 PM

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 ?

SDPhantom 05-17-19 04:26 PM

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.

doofus 06-17-19 04:08 AM

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.


All times are GMT -6. The time now is 05:00 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI