Skip to content

Instantly share code, notes, and snippets.

@fuba
Created June 7, 2020 12:30
Show Gist options
  • Save fuba/267a1046da7ed7214bb809c44b42ab27 to your computer and use it in GitHub Desktop.
Save fuba/267a1046da7ed7214bb809c44b42ab27 to your computer and use it in GitHub Desktop.
Scrolling by trackball with clicking middle button using Hammerspoon
-- HANDLE SCROLLING
local deferred = false
overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e)
--print("down"))
deferred = true
return true
end)
overrideOtherMouseUp = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e)
-- print("up"))
if (deferred) then
overrideOtherMouseDown:stop()
overrideOtherMouseUp:stop()
hs.eventtap.otherClick(e:location())
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
return true
end
return false
end)
local oldmousepos = {}
local scrollmult = -4 -- negative multiplier makes mouse work like traditional scrollwheel
dragOtherToScroll = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDragged }, function(e)
-- print("scroll");
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)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment