forked from jasonrudolph/keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scroll using middle-click + mouse-movement
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED | ||
local scrollMouseButton = 2 | ||
local deferred = false | ||
|
||
-- Load the mouse extension before having go use it. | ||
-- If it is loaded on first use, the delay can lead to problems. | ||
hs.mouse.getAbsolutePosition() | ||
|
||
overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e) | ||
-- print("down") | ||
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber']) | ||
if scrollMouseButton == pressedMouseButton | ||
then | ||
deferred = true | ||
return true | ||
end | ||
end) | ||
|
||
overrideOtherMouseUp = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e) | ||
-- print("up") | ||
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber']) | ||
if scrollMouseButton == pressedMouseButton | ||
then | ||
if (deferred) then | ||
overrideOtherMouseDown:stop() | ||
overrideOtherMouseUp:stop() | ||
hs.eventtap.otherClick(e:location(), pressedMouseButton) | ||
overrideOtherMouseDown:start() | ||
overrideOtherMouseUp:start() | ||
return true | ||
end | ||
return false | ||
end | ||
return false | ||
end) | ||
|
||
local oldmousepos = {} | ||
local scrollmult = -4 -- negative multiplier makes mouse work like traditional scrollwheel | ||
|
||
dragOtherToScroll = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDragged }, function(e) | ||
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber']) | ||
-- print ("pressed mouse " .. pressedMouseButton) | ||
if scrollMouseButton == pressedMouseButton | ||
then | ||
-- print("scroll"); | ||
deferred = false | ||
oldmousepos = hs.mouse.getAbsolutePosition() | ||
|
||
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) | ||
|
||
overrideOtherMouseDown:start() | ||
overrideOtherMouseUp:start() | ||
dragOtherToScroll:start() |