Last active
July 21, 2024 18:06
-
-
Save cwagner22/13e772cda1c4ad80d23452e530f4b760 to your computer and use it in GitHub Desktop.
Hammerspoon script to scroll with right click + trackball. Tested with MX Ergo.
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
-- https://github.com/tekezo/Karabiner/issues/814 | |
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED | |
local scrollMouseButton = 2 | |
local deferred = false | |
overrideOtherMouseDown = | |
hs.eventtap.new( | |
{hs.eventtap.event.types.rightMouseDown}, | |
function(e) | |
deferred = true | |
return true | |
end | |
) | |
overrideOtherMouseUp = | |
hs.eventtap.new( | |
{hs.eventtap.event.types.rightMouseUp}, | |
function(e) | |
if (deferred) then | |
overrideOtherMouseDown:stop() | |
overrideOtherMouseUp:stop() | |
hs.eventtap.rightClick(e:location(), pressedMouseButton) | |
overrideOtherMouseDown:start() | |
overrideOtherMouseUp:start() | |
return true | |
end | |
return false | |
end | |
) | |
local oldmousepos = {} | |
local scrollmult = -6 -- negative multiplier makes mouse work like traditional scrollwheel | |
dragOtherToScroll = | |
hs.eventtap.new( | |
{hs.eventtap.event.types.rightMouseDragged}, | |
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 | |
) | |
overrideOtherMouseDown:start() | |
overrideOtherMouseUp:start() | |
dragOtherToScroll:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment