Created
March 15, 2021 13:12
-
-
Save kdnk/0ad80f6b7cbf9070110aed944ac27f3c to your computer and use it in GitHub Desktop.
[Hammerspoon] tackboll scroll & reload with simultaneously (left & right) click
This file contains 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
-------------------------------------------------------------- | |
-- HANDLE SCROLLING & RELOAD | |
-------------------------------------------------------------- | |
-- ref. https://github.com/tekezo/Karabiner/issues/814#issuecomment-337643019 | |
local shouldFireOriginalRightMouseDown = false | |
local leftDowned = false | |
local rightDowned = false | |
overrideLeftMouseDown = hs.eventtap.new({ hs.eventtap.event.types.leftMouseDown }, function(e) | |
leftDowned = true | |
if (rightDowned) then | |
hs.eventtap.keyStroke({"cmd"}, "r") | |
shouldFireOriginalRightMouseDown = false | |
leftDowned = false | |
rightDowned = false | |
return true | |
else | |
return false | |
end | |
end) | |
overrideLeftMouseUp = hs.eventtap.new({ hs.eventtap.event.types.leftMouseUp }, function(e) | |
leftDowned = false | |
end) | |
overrideRightMouseDown = hs.eventtap.new({ hs.eventtap.event.types.rightMouseDown }, function(e) | |
rightDowned = true | |
if (leftDowned) then | |
hs.eventtap.keyStroke({"cmd"}, "r") | |
shouldFireOriginalRightMouseDown = false | |
leftDowned = false | |
rightDowned = false | |
else | |
shouldFireOriginalRightMouseDown = true | |
end | |
return true | |
end) | |
overrideRightMouseUp = hs.eventtap.new({ hs.eventtap.event.types.rightMouseUp }, function(e) | |
rightDowned = false | |
if (shouldFireOriginalRightMouseDown) then | |
overrideLeftMouseDown:stop() | |
overrideLeftMouseUp:stop() | |
overrideRightMouseDown:stop() | |
overrideRightMouseUp:stop() | |
hs.eventtap.rightClick(e:location()) | |
overrideLeftMouseDown:start() | |
overrideLeftMouseUp:start() | |
overrideRightMouseDown:start() | |
overrideRightMouseUp:start() | |
return true | |
end | |
return false | |
end) | |
local oldmousepos = {} | |
local scrollmult = -4 -- negative multiplier makes mouse work like traditional scrollwheel | |
dragRightToScroll = hs.eventtap.new({ hs.eventtap.event.types.rightMouseDragged }, function(e) | |
-- print("scroll"); | |
shouldFireOriginalRightMouseDown = false | |
oldmousepos = hs.mouse.absolutePosition() | |
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.absolutePosition(oldmousepos) | |
return true, {scroll} | |
end) | |
overrideRightMouseDown:start() | |
overrideRightMouseUp:start() | |
overrideLeftMouseDown:start() | |
overrideLeftMouseUp:start() | |
dragRightToScroll:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment