Keybind Rename Lua Script

I found a script that replaces keybind names on action bars with ones of your choosing, but the names seem to revert to default on /reload. Maybe someone can make it update on reload?

local function updatehotkey(self, actionButtonType)
    local hotkey = _G[self:GetName() .. 'HotKey']
    local text = hotkey:GetText()

    text = string.gsub(text, '(s%-)', 'S')
    text = string.gsub(text, '(a%-)', 'A')
    text = string.gsub(text, '(c%-)', 'C')
    text = string.gsub(text, '(Mouse Button )', 'M')
    text = string.gsub(text, '(Middle Mouse)', 'M3')
    text = string.gsub(text, '(Num Pad )', 'N')
    text = string.gsub(text, '(Page Up)', 'PU')
    text = string.gsub(text, '(Page Down)', 'PD')
    text = string.gsub(text, '(Spacebar)', 'SpB')
    text = string.gsub(text, '(Insert)', 'Ins')
    text = string.gsub(text, '(Home)', 'Hm')
	text = string.gsub(text, '(Y)', '1')
	text = string.gsub(text, '(U)', '2')
	text = string.gsub(text, '(I)', '3')
	text = string.gsub(text, '(O)', '4')
	text = string.gsub(text, '(P)', '5')
	text = string.gsub(text, '(H)', '6')
	text = string.gsub(text, '(J)', '7')
	text = string.gsub(text, '(K)', '8')
	text = string.gsub(text, '(L)', '9')
	text = string.gsub(text, '(B)', '10')
	text = string.gsub(text, '(N)', '11')
	text = string.gsub(text, '(M)', '12')

    hotkey:SetText(text)
end
hooksecurefunc("ActionButton_UpdateHotkeys", updatehotkey)

You could force an update after the hook by adding

ActionBarButtonEventsFrame:GetScript("OnEvent")(ActionBarButtonEventsFrame, "UPDATE_BINDINGS")

1 Like

Works perfectly, thank you. I think you’re the one who helped me with this one as well:

If you have any feedback to give on that post, I would greatly appreciate it.

Does anyone know how to get this to work again in 9.0 ?

I don’t, but I’m trying to solve this as well. I’m not a programmer but back in the late 90s early 2000s I pretended to be one for the purposes of writing my own fancy macro scripts for Ultima Online. I can sort of read code, but not really.

As best I can tell, the problem with addons that do this is the fact that “ActionButton_UpdateHotkeys” and others like it are no longer functions in the Blizzard API?

I have found references online that say the new function is ActionBarActionButtonMixinbut I can’t find any official documentation at all.

Frankly, I don’t know how addon authors do anything without a manual. Where is the official (or unofficial) instruction manual on various functions?

I found this page, but I’m not sure if that’s just some dude’s code or if it is the actual Blizzard code which contains clues on how to restore our hotkey-hiding addons: https://github.com/tomrus88/BlizzardInterfaceCode/blob/master/Interface/FrameXML/ActionButton.lua

I’m sure there are working addons or total overhauls that do this, like ElvUI or even things like Bartender, so if anyone sees this thread and uses something that successfully hides hotkeys after 9.0, post it and maybe I can dig through that addon code to try and figure it out.

I’ve been looking around as well since I’ve recently returned to the game since Legion. I had ripped some code/script similar to op’s from somewhere back then and turned it into a simple addon.
Same as you guys, no longer working presumably because these no longer exist.(?)

hooksecurefunc("ActionButton_UpdateHotkeys", updatehotkey)
hooksecurefunc("ActionButton_OnEvent", function(self, event, ...)

So I was trying to dig around and like you said similar addons accomplish the same but I couldn’t find anything similar in Bartender4 or Dominos addons. I did find some in ElvUI though. It looks pretty similar but like you said Dabeard, ActionButton_UpdateHotkeys seems deprecated as it is nowhere to be found. I couldn’t find anything related to ActionBarActionButtonMixin in there either so I’m at a loss at this point. If you or anyone else wants to take a deeper look the code is at ElvUI/Modules/ActionBars/ActionBars.lua. Hope I could be helpful or point someone in the right direction.

function AB:FixKeybindText(button)
local hotkey = _G[button:GetName()..'HotKey']
local text = hotkey:GetText()

local hotkeyPosition = E.db.actionbar.hotkeyTextPosition or 'TOPRIGHT'
local hotkeyXOffset = E.db.actionbar.hotkeyTextXOffset or 0
local hotkeyYOffset =  E.db.actionbar.hotkeyTextYOffset or -3

local justify = 'RIGHT'
if hotkeyPosition == 'TOPLEFT' or hotkeyPosition == 'BOTTOMLEFT' then
	justify = 'LEFT'
elseif hotkeyPosition == 'TOP' or hotkeyPosition == 'BOTTOM' then
	justify = 'CENTER'
end

if text then
	text = gsub(text, 'SHIFT%-', L["KEY_SHIFT"])
	text = gsub(text, 'ALT%-', L["KEY_ALT"])
	text = gsub(text, 'CTRL%-', L["KEY_CTRL"])
	text = gsub(text, 'BUTTON', L["KEY_MOUSEBUTTON"])
	text = gsub(text, 'MOUSEWHEELUP', L["KEY_MOUSEWHEELUP"])
	text = gsub(text, 'MOUSEWHEELDOWN', L["KEY_MOUSEWHEELDOWN"])
	text = gsub(text, 'NUMPAD', L["KEY_NUMPAD"])
	text = gsub(text, 'PAGEUP', L["KEY_PAGEUP"])
	text = gsub(text, 'PAGEDOWN', L["KEY_PAGEDOWN"])
	text = gsub(text, 'SPACE', L["KEY_SPACE"])
	text = gsub(text, 'INSERT', L["KEY_INSERT"])
	text = gsub(text, 'HOME', L["KEY_HOME"])
	text = gsub(text, 'DELETE', L["KEY_DELETE"])
	text = gsub(text, 'NMULTIPLY', '*')
	text = gsub(text, 'NMINUS', 'N-')
	text = gsub(text, 'NPLUS', 'N+')
	text = gsub(text, 'NEQUALS', 'N=')

	hotkey:SetText(text)
	hotkey:SetJustifyH(justify)
end

Something to try using the OP code

local function updatehotkey(self, actionButtonType)
    local hotkey = _G[self:GetName() .. 'HotKey']
    local text = hotkey:GetText()

    text = string.gsub(text, '(s%-)', 'S')
    text = string.gsub(text, '(a%-)', 'A')
    text = string.gsub(text, '(c%-)', 'C')
    text = string.gsub(text, '(Mouse Button )', 'M')
    text = string.gsub(text, '(Middle Mouse)', 'M3')
    text = string.gsub(text, '(Num Pad )', 'N')
    text = string.gsub(text, '(Page Up)', 'PU')
    text = string.gsub(text, '(Page Down)', 'PD')
    text = string.gsub(text, '(Spacebar)', 'SpB')
    text = string.gsub(text, '(Insert)', 'Ins')
    text = string.gsub(text, '(Home)', 'Hm')
	text = string.gsub(text, '(Y)', '1')
	text = string.gsub(text, '(U)', '2')
	text = string.gsub(text, '(I)', '3')
	text = string.gsub(text, '(O)', '4')
	text = string.gsub(text, '(P)', '5')
	text = string.gsub(text, '(H)', '6')
	text = string.gsub(text, '(J)', '7')
	text = string.gsub(text, '(K)', '8')
	text = string.gsub(text, '(L)', '9')
	text = string.gsub(text, '(B)', '10')
	text = string.gsub(text, '(N)', '11')
	text = string.gsub(text, '(M)', '12')

    hotkey:SetText(text)
end
hooksecurefunc(ActionBarActionButtonMixin, "UpdateHotkeys", updatehotkey)

ActionBarButtonEventsFrame:GetScript("OnEvent")(ActionBarButtonEventsFrame, "UPDATE_BINDINGS")

local map = {
	["Middle Mouse"] = "M3",
	["Mouse Wheel Down"] = "DWN",
	["Mouse Wheel Up"] = "UP",
    ["Home"] = "Hm",
    ["Insert"] = "Ins",
    ["Page Down"] = "PD",
    ["Page Up"] = "PU",
    ["Spacebar"] = "SpB",
}

local patterns = {
	["Mouse Button "] = "M", -- M4, M5
	["Num Pad "] = "N",
	["a%-"] = "A", -- alt
	["c%-"] = "C", -- ctrl
	["s%-"] = "S", -- shift
}

local bars = {
	"ActionButton",
	"MultiBarBottomLeftButton",
	"MultiBarBottomRightButton",
	"MultiBarLeftButton",
	"MultiBarRightButton",
}

local function UpdateHotkey(self, actionButtonType)
	local hotkey = self.HotKey
	local text = hotkey:GetText()
	for k, v in pairs(patterns) do
		text = text:gsub(k, v)
	end
	hotkey:SetText(map[text] or text)
end

for _, bar in pairs(bars) do
	for i = 1, NUM_ACTIONBAR_BUTTONS do
		hooksecurefunc(_G[bar..i], "UpdateHotkeys", UpdateHotkey)
	end
end
3 Likes

Awesome, thank you. This one worked for me. I couldn’t get the other one posted work. Any chance this could work with the petbar or extra action button that appears in the middle of the screen sometimes? No big deal if not but great work and thanks so much for posting a working fix to this.

Sorry for necro but this post still works for dragonflight ,just make sure you update your toc to 100002 . but I also wanted to ask if anyone knows . How can I rename a Shift mouse wheel up and Shift Mouse Wheel down keybind to SMwU and SMwD

i think this will work maybe for mousewheel keys with shift modifier

local map = {
	["Middle Mouse"] = "M3",
	["Mouse Wheel Down"] = "DWN",
	["Mouse Wheel Up"] = "UP",
    ["Home"] = "Hm",
    ["Insert"] = "Ins",
    ["Page Down"] = "PD",
    ["Page Up"] = "PU",
    ["Spacebar"] = "SpB",
}

local patterns = {
	["Mouse Wheel Down"] = "MwD",
	["Mouse Wheel Up"] = "MwU",
	["Mouse Button "] = "M", -- M4, M5
	["Num Pad "] = "N",
	["a%-"] = "A", -- alt
	["c%-"] = "C", -- ctrl
	["s%-"] = "S", -- shift
}

local bars = {
	"ActionButton",
	"MultiBarBottomLeftButton",
	"MultiBarBottomRightButton",
	"MultiBarLeftButton",
	"MultiBarRightButton",
}

local function UpdateHotkey(self, actionButtonType)
	local hotkey = self.HotKey
	local text = hotkey:GetText()
	for k, v in pairs(patterns) do
		text = text:gsub(k, v)
	end
	hotkey:SetText(map[text] or text)
end

for _, bar in pairs(bars) do
	for i = 1, NUM_ACTIONBAR_BUTTONS do
		hooksecurefunc(_G[bar..i], "UpdateHotkeys", UpdateHotkey)
	end
end
2 Likes

You sir are a true hero i put this in World of Warcraft: AddOn Creator website and made a app in seconds thanks

To extend this to all 8 bars available, the local bars block needs to be updated to:

local bars = {
“ActionButton”,
“MultiBarBottomLeftButton”,
“MultiBarBottomRightButton”,
“MultiBarLeftButton”,
“MultiBarRightButton”,
“MultiBar5Button”,
“MultiBar6Button”,
“MultiBar7Button”,
}

Hi, this works for wotlk?