Button:RegisterForClicks
Jump to navigation
Jump to search
Registers the button widget to receive OnClick script events.
Button:RegisterForClicks([button1, ...])
Arguments
- button1, ...
- string? - A list of combinations of mouse buttons and their click action.
AnyUp
- Responds to the up action of any mouse button.AnyDown
- Responds to the down action of any mouse button.LeftButtonUp
,LeftButtonDown
RightButtonUp
,RightButtonDown
MiddleButtonUp
,MiddleButtonDown
Button4Up
,Button4Down
Button5Up
,Button5Down
Details
- The default button registered on new button objects is
LeftButtonUp
. - Pass multiple arguments to register several buttons, or none to remove any previous registrations. Subsequent calls replace any prior ones.
- Controls the OnClick, PreClick, PostClick, and OnDoubleClick script events.
- Does not control the OnMouseDown, OnMouseUp, and OnDragStart script events.
Example
Creates a button that responds to all mouse button clicks.
local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
btn:SetPoint("CENTER")
btn:SetSize(100, 40)
btn:SetText("Click me")
-- "LeftButtonUp" is the default behavior
btn:RegisterForClicks("AnyDown", "AnyUp")
-- only the OnClick script is affected by .RegisterForClicks
btn:SetScript("OnClick", function(self, button, down)
print("OnClick", button, down)
end)