Skip to content

Instantly share code, notes, and snippets.

@eutobias
Last active May 6, 2024 13:42
Show Gist options
  • Save eutobias/d2964e769369e615fb620a1623834fac to your computer and use it in GitHub Desktop.
Save eutobias/d2964e769369e615fb620a1623834fac to your computer and use it in GitHub Desktop.
Hammerspoon config for horizontal scroll on mouse middle button click
-- Bases in some codes i found on internet
-- but i din't find the links again
-- HANDLE SCROLLING
local scrollmultHorizontal = 2
local scrollmultVertical = 2 -- not used if use only horizontal scroll
local middleMouseEventButtonNumber = 2
hs.eventtap.new(
{"all"},
function(e)
-- Debug to find your middle mouse button number
-- print(
-- "mouse:",
-- e:getProperty(hs.eventtap.event.properties["mouseEventButtonNumber"])
-- )
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties["mouseEventButtonNumber"])
local shouldScroll = middleMouseEventButtonNumber == pressedMouseButton
if shouldScroll then
-- if you want vertical scroll too uncomment line bellow
-- local dy = e:getProperty(hs.eventtap.event.properties["mouseEventDeltaY"])
local dx = e:getProperty(hs.eventtap.event.properties["mouseEventDeltaX"])
-- if you want vertical scroll too comment line bellow
hs.eventtap.event.newScrollEvent({dx * scrollmultHorizontal, 0}, {}, "pixel"):post()
-- if you want vertical scroll too uncomment line bellow
-- hs.eventtap.event.newScrollEvent({dx * scrollmultHorizontal, dy * scrollmultVertical}, {}, "pixel"):post()
return true, {scroll}
else
return false, {}
end
end
):start()
-- CMD + ALT + CTRL + R to reload config
hs.hotkey.bind(
{"cmd", "alt", "ctrl"},
"R",
function()
hs.reload()
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment