Skip to content

Instantly share code, notes, and snippets.

@Astroneko404
Last active September 8, 2022 12:06
Show Gist options
  • Save Astroneko404/caf657bc2c1c0cf16fae8f31c08f4867 to your computer and use it in GitHub Desktop.
Save Astroneko404/caf657bc2c1c0cf16fae8f31c08f4867 to your computer and use it in GitHub Desktop.
[Archive] Use button4 & cursor to scroll (for my Logitech Trackman Marble)
-- HANDLE SCROLLING
local oldmousepos = {}
-- positive multiplier (== natural scrolling) makes mouse work like traditional scrollwheel
local scrollmult = 4
-- The were all events logged, when using `{"all"}`
mousetap = hs.eventtap.new({0,3,5,14,25,26,27}, function(e)
oldmousepos = hs.mouse.getAbsolutePosition()
local mods = hs.eventtap.checkKeyboardModifiers()
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
-- If OSX button 4 is pressed, allow scrolling
local shouldScroll = 3 == pressedMouseButton
if shouldScroll 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')
scroll:post()
-- put the mouse back
hs.mouse.setAbsolutePosition(oldmousepos)
return true, {scroll}
else
return false, {}
end
-- print ("Mouse moved!")
-- print (dx)
-- print (dy)
end)
mousetap:start()
@Astroneko404
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment