Created
June 7, 2020 12:30
-
-
Save fuba/267a1046da7ed7214bb809c44b42ab27 to your computer and use it in GitHub Desktop.
Scrolling by trackball with clicking middle button using Hammerspoon
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
-- 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