Getting key binding from spell name

Let’s say I have Flash of Light bound to “F3” key.
Is it possible to write a function to return the key from the spell name as input?

For example my input is
Flash of Light
The output should be the key or combination of keys that the spell is bound to (i.e “F3” or “Shift+4”)
if the spell isn’t bounded, return nil

Yes, but it’s complex.

The addon I’m working on does exactly this, but the code has got a ton of error checking in it that won’t make sense in this context. Lemme strip it out and I’ll post it.

Thank you, please post it when you can

Sorry, gonna have to finish this wednesday. I’m out of steam tonight and three doc appts tomorrow.

I will get it to you, just not right this sec.

I know I promised this by today but life has gotten ahead of me all day and I’m jsut now settling down.

I’ll try tomorrow.

It’s definately doable.

It’s convoluted as heck, but it’s doable.

Essentialy (in case you want to take a whack at it yourself), you need to cross reference a list of bind commands to a list of keys that execute them.

local binds, keys, command = {}, {}
for i = 1, GetNumBindings() do
  binds[i] = {GetBindInfo(i)}
  if #binds[i] > 2 then
    for k, v in ipairs(binds[i]) do
    if     k = 1 then
      command = v
    elseif k = 2 then
    else
      keys[v] = command
    end
end

The keys table here maps the key values to the command (the native data is mapped the other way around - commands to key values).

The commands you’re going to be interested in are the ones that are button names.

Button names are things like ACTIONBUTTON1 and MULTIACTIONBAR1BUTTON3.

What’s missing is a map between the button names and the action slots.

Blizzard’s native system is an unbelievable mess in this regards.

That paging bar nonsense mucks up the mapping from action slot to action button terribly.

So the action that’s on a button NOW might not be the action on that button when you change bar paging.

However, for those buttons that are NOT on paging bars you would want to poll the action slot that corresponds to that button and capture the spell that’s there.

Understand, not everything on an action button is a spell. Mounts, pets, toys, items, macros, flyouts all get handled differently so as you build your data for this, you’ll need to know how you want to deal with each.

Some of them aren’t very well documented (some aren’t documented at all).

Essentially, though, you’d want to take the action slots and spin through them and build a table by action slot of what spell is there (assuming we’re talking just spells).

So, ACTIONBUTTON1 assigned to ACTIONSLOT1 has Bunny Fling on it (at least until you swap paging bars).

You know ACTIONBUTTON1 is bound to your 7 key (for example) from the keys table above.

From here, it’s just a matter of creating a cross-reference between the spells in the action slots with the keys for the action buttons - assuming you can map action slots to action buttons at all (very complicated for vanilla, simpler for ElvUI, Bartender, Dominos).

This process of mapping from key value to action name is the core process of a Weak Auras replacement I’ve been working on for a couple of years.

It’s an incredible mess trying to do this.

But I think it’s worth it.

I want to be able to define a visual representation of my input suite on screen and see what is set to execute for each key. If there is a macro on that will execute, I want it parsed and I want to know what will execute based on the conditionals then in play. If that macro branches to another one, I want to know what the most significant thing is that will execute. I want my cooldowns and counts and such all to be mirrored on that visual representation so I can see, easily, what is ready, what is not, and where, relative to my fingers, each ability I need is.

At one point I had all of this working within Weak Auras, but the overhead of that addon was so high that it wasn’t workable in stressful content.

I had all of this working as a stand-alone add-on last year but dropped out of the game for a bit to deal with cancer.

When I came back it was near to 8.0 and 8.0 broke just about everything I was doing so I had to start over on most of it.

I’m getting closer.

I’ve got the macro parsing working flawlessly.

I can deal with anything that can be dropped on a button.

I’ve got the mapping done between the button names and the action slots for both ElvUI and Bartender4 (I’m not doing Dominos - I dug around in that code and it’s a nasty mess that I’m just not going to attempt to decipher and I’m not doing vanilla - anyone who wants to use my addon will likely have custom input devices and a bar mod anyway - trying to deal with that gawdawful paging bar system and shuffling action slots around is a nightmare).

I’m in the middle of a low-energy remodel of my living area so my girlfriend can move in near the end of the month and I’m still not quite up to par after my cancer treatment so I have to make energy choices.

I’m hoping that it’ll all be done by August.

Thank you for the detailed explanation. It will probably take some time for me to fully understand your algorithm. The immediate question I have is by
GetBindInfo, do you mean GetActionInfo? I couldn’t find GetBindInfo in the API.

Do you have a name for your addon? Would love to try it out when it’s released. I hope you triumph over the disease that’s ailing you.