Question about: hooksecurefunc("UpdateHotkey")

what would I need to change to make this work in TBC classic, it says “UpdateHotkey” isn’t a function.

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], “UpdateHotkey”, UpdateHotkey)
end
end

I haven’t checked the actual code will work as a replacement with the classic/TBC versions(s) but the closest 1-to-1 change I could find would be to replace:

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

with

hooksecurefunc("ActionButton_UpdateHotkeys", UpdateHotkey)

It looks like they replaced some single action button functions with a mixin at some point for retail. It means you could also get rid of the bars table if you wanted to.

Basically what fizzlemizz already said

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 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

hooksecurefunc("ActionButton_UpdateHotkeys", UpdateHotkey)
1 Like

ty both

/10char