Skip to content

Instantly share code, notes, and snippets.

@greneholt
Created January 17, 2021 01:23
Show Gist options
  • Save greneholt/6021471456c81aec978a59bf90eb9a81 to your computer and use it in GitHub Desktop.
Save greneholt/6021471456c81aec978a59bf90eb9a81 to your computer and use it in GitHub Desktop.
-- HANDLE SCROLLING
-- positive multiplier (== natural scrolling) makes mouse work like traditional scrollwheel
local scrollmult = -4
-- mouselog = hs.eventtap.new({'all'}, function(e)
-- print("event " .. e:getType())
-- end)
-- mouselog:start()
-- The were all events logged, when using `{"all"}`
mousetap = hs.eventtap.new({25,26,27}, function(e)
local oldmousepos = hs.mouse.getAbsolutePosition()
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
-- print("event " .. e:getType() .. " mousebutton " .. pressedMouseButton)
-- If OSX button 4 is pressed, allow scrolling
if pressedMouseButton == 3 then
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}
else
return false, {}
end
end)
mousetap:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment