Skip to content

Enum MouseButton ​

A pointer button, as in event.button and pointer:button. The Button global holds the named ones.

lua
wm.input:on("pointer_button", function(event)
	if event.button == Button.Middle and event.state == "Pressed" and event.modifiers.super then
		local target = event.pointer:window_under()
		if target then target.box:raise() end
	end
end)

Errors for any other name, such as Button.Side.

Values ​

Button.LeftLeft ​

Code 272.

Code 273.

Button.MiddleMiddle ​

Code 274, pressing the wheel on most mice.

Button.BackBack ​

Code 278.

  • Most mice send their back side button as 275. Both are named "Back" and both == Button.Back.
  • pointer:button(Button.Back, ...) sends 278.

Button.ForwardForward ​

Code 277.

  • Most mice send their forward side button as 276. Both are named "Forward" and both == Button.Forward.
  • pointer:button(Button.Forward, ...) sends 277.

Operators ​

button == other -> booleanbutton == other ​

True when other is a MouseButton with the same code or the same name.

  • Lua only calls this when both sides are userdata, so event.button == "Left" and event.button == 272 are always false. Use tostring(button) for names.

tostring(button) -> stringtostring ​

The button's name: "Left", "Right", "Middle", "Back" or "Forward".

  • "Unknown(code)" for any other button, such as "Unknown(279)".

button .. value -> stringbutton .. value ​

The name joined with value turned into text, on either side.

lua
local label = "pressed " .. Button.Left

Codes ​

Wherever Hazel takes a MouseButton, a Linux input code works too: pointer:button(275, "pressed") presses the side button. pointer:buttons() returns codes, not MouseButton values.