Hi all
As promised I am posting my working code here for other novices like myself.
Toc
Lua Code:
## Title: AAA |cffff0000 Testing Ground
## Interface: 80300
## Notes: |cffff0000 Testing Ground
## Version: AAA
## Date: Friday 21 August 2020
## SavedVariables: TableOfItems
Lua
Lua Code:
local myTestingKeybindingItemName, myTestingKeybindingItemLink, myTestingKeybindingItemID
local function addItemToTable(itemLink)
if not myTestingKeybindingTableOfItems then
myTestingKeybindingTableOfItems = {}
end
local found
for k, v in pairs(myTestingKeybindingTableOfItems) do
if v == itemLink then
print('Item all ready listed')
found = true
break
end
end
if not found then
table.insert(myTestingKeybindingTableOfItems, 1, itemLink)
print('Item added to list', itemLink)
end
end
local function keybindingButtonSetUp()
print('*** keybinding setup function fired ***')
local myTestingKeybindingButton = CreateFrame('BUTTON', 'WalkerbomyTest')
SetBindingClick('CTRL-\[', 'WalkerbomyTest', 'b1')
SetBindingClick('CTRL-\]', 'WalkerbomyTest', 'b2')
SetBindingClick('CTRL-\\', 'WalkerbomyTest', 'b3')
SetBindingClick('SHIFT-\[', 'WalkerbomyTest', 'b4')
SetBindingClick('SHIFT-\]', 'WalkerbomyTest', 'b5')
SetBindingClick('SHIFT-\\', 'WalkerbomyTest', 'b6')
myTestingKeybindingButton:SetScript(
'OnClick',
function(self, button)
if button == 'b1' then
print('CTRL-\[ button clicked', myTestingKeybindingItemLink)
addItemToTable(myTestingKeybindingItemLink)
elseif button == 'b2' then
print('CTRL-\] button clicked', myTestingKeybindingItemLink)
elseif button == 'b3' then
print('CTRL-\\ button clicked', myTestingKeybindingItemLink)
elseif button == 'b4' then
print('SHIFT-\] button clicked', myTestingKeybindingItemLink)
elseif button == 'b5' then
print('SHIFT-\\ button clicked', myTestingKeybindingItemLink)
elseif button == 'b6' then
print('SHIFT-\] button clicked', myTestingKeybindingItemLink)
end
end
)
end
SLASH_MYTEST1 = '/qwe'
function SlashCmdList.MYTEST(msg, editbox)
if #myTestingKeybindingTableOfItems == 0 then
print('empty table')
else
for k, v in pairs(myTestingKeybindingTableOfItems) do
print('item', k, v)
end
end
end
SLASH_MYTESTC1 = '/asd'
function SlashCmdList.MYTESTC(msg, editbox)
myTestingKeybindingTableOfItems = {}
print('List cleared')
end
GameTooltip:HookScript(
'OnTooltipSetItem',
function(self)
myTestingKeybindingItemName, myTestingKeybindingItemLink = self:GetItem()
myTestingKeybindingItemID = tonumber(strmatch(myTestingKeybindingItemLink, 'item:(%d+):'))
end
)
local myTestingKeybindingFrame = CreateFrame('FRAME', 'WalkerboFrame')
myTestingKeybindingFrame:SetScript(
'OnEvent',
function(self, event, ...)
if event == 'PLAYER_LOGIN' then
print('*** Addon Loaded ***')
keybindingButtonSetUp()
end
end
)
myTestingKeybindingFrame:RegisterEvent('PLAYER_LOGIN')
I will now start working out how to add these keybindings to the in-game keybinding UI.
Thanks to you all for your help, it is most appreciated.