Created
July 14, 2020 20:57
-
-
Save zuigon/b09f04c68855ac4dbb55bcf4b94ea770 to your computer and use it in GitHub Desktop.
hammerspoon middle scroll
This file contains 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
-- MacOS middle-click scroll | |
local deferred = false | |
overrideRightMouseDown = hs.eventtap.new({ hs.eventtap.event.types.middleMouseDown }, function(e) | |
deferred = true | |
return true | |
end) | |
overrideRightMouseUp = hs.eventtap.new({ hs.eventtap.event.types.middleMouseUp }, function(e) | |
if (deferred) then | |
overrideRightMouseDown:stop() | |
overrideRightMouseUp:stop() | |
hs.eventtap.rightClick(e:location()) | |
overrideRightMouseDown:start() | |
overrideRightMouseUp:start() | |
return true | |
end | |
return false | |
end) | |
local oldmousepos = {} | |
local scrollmult = -4 -- negative multiplier makes mouse work like traditional scrollwheel | |
dragRightToScroll = hs.eventtap.new({ hs.eventtap.event.types.middleMouseDragged }, function(e) | |
deferred = false | |
oldmousepos = hs.mouse.getAbsolutePosition() | |
local dx = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaX']) | |
local dy = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaY']) | |
local scroll = hs.eventtap.event.newScrollEvent({-dx * scrollmult, -dy * scrollmult},{},'pixel') | |
-- put the mouse back | |
hs.mouse.setAbsolutePosition(oldmousepos) | |
return true, {scroll} | |
end) | |
overrideRightMouseDown:start() | |
overrideRightMouseUp:start() | |
dragRightToScroll:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment