Skip to content

Instantly share code, notes, and snippets.

@ParatechX
Created November 2, 2018 21:30
Show Gist options
  • Save ParatechX/c03c1146f7cd719dbfd65a337c7228f3 to your computer and use it in GitHub Desktop.
Save ParatechX/c03c1146f7cd719dbfd65a337c7228f3 to your computer and use it in GitHub Desktop.
Hammerspoon/Lua script to enable 2d scrolling on key(CTRL) press
-- SCROLL ON MOUSE MOVEMENT WHEN CTRL BUTTON DOWN
-- inspired by
-- https://superuser.com/questions/303424/can-i-enable-scrolling-with-middle-button-drag-in-os-x
--
-- add to hammerspoon config and hit hs.reload()
local scrollModifier = "ctrl"
local oldMousePosition = {}
local scrollIntensity = 4
ctrlDownMouseTracker = hs.eventtap.new({ hs.eventtap.event.types.mouseMoved }, function(e)
oldMousePosition = hs.mouse.getAbsolutePosition()
local dX = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaX'])
local dY = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaY'])
hs.eventtap.scrollWheel({dX * scrollIntensity , dY * scrollIntensity }, {})
-- put the mouse back
hs.mouse.setAbsolutePosition(oldMousePosition)
end)
dragCtrlToScroll = hs.eventtap.new({ hs.eventtap.event.types.flagsChanged }, function(e)
local modifiers = e:getFlags()
if ( modifiers[ scrollModifier ] )
then
ctrlDownMouseTracker:start()
else
ctrlDownMouseTracker:stop()
end
end)
dragCtrlToScroll:start()
@ParatechX
Copy link
Author

Using it on mac with external keyboard that has built in trackball. Not the same as trackpad, but creates reasonable emulation of scroll experience.

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