You can hook
ContainerFrameItemButton_OnClick() for normal clicks and
ContainerFrameItemButton_OnModifiedClick() for modified ones (Example: Shift-Click). To get the bag and slot numbers from these, you need to do something like this.
Lua Code:
hooksecurefunc("ContainerFrameItemButton_OnClick",function(self,button)
local bag,slot=self:GetParent():GetID(),self:GetID();
-- Do stuff here
end);
Note: Both left and right mouse buttons are already in use by the game. Left lets you move the item while right will equip the weapon you want to click. If you register extra buttons to be recognized as clicks, these functions will pick up the extra buttons as right-clicks. There are better ways of detecting a weapon swap if that's your goal instead. Also keep in mind, macros cannot be edited while in combat, though weapon swapping cannot happen during combat either.
Another option is to use the
[equipped] macro conditional. See
Macro Conditionals.