Last active
May 6, 2024 13:42
-
-
Save eutobias/d2964e769369e615fb620a1623834fac to your computer and use it in GitHub Desktop.
Hammerspoon config for horizontal scroll on mouse middle button click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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