Created
November 2, 2018 21:30
-
-
Save ParatechX/c03c1146f7cd719dbfd65a337c7228f3 to your computer and use it in GitHub Desktop.
Hammerspoon/Lua script to enable 2d scrolling on key(CTRL) press
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
-- 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using it on mac with external keyboard that has built in trackball. Not the same as trackpad, but creates reasonable emulation of scroll experience.