owenlo / marble-hammerspoon Goto Github PK
View Code? Open in Web Editor NEWScroll wheel code for Logitech Marble Trackball
Scroll wheel code for Logitech Marble Trackball
The methods hs.mouse.getAbsolutePosition
and hs.mouse.setAbsolutePosition
are now deprecated. Instead, we need to use hs.mouse.absolutePosition
.
Here is corrected code that addresses that problem:
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED
local backMouseButton = 3
local forwardMouseButton = 4
local deferred = false
function setOverrides(e)
overrideOtherMouseDown:stop()
overrideOtherMouseUp:stop()
hs.eventtap.otherClick(e:location(), 0, pressedMouseButton)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
end
overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if backMouseButton == pressedMouseButton or forwardMouseButton == pressedMouseButton
then
deferred = true
return true
end
end)
overrideOtherMouseUp = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if backMouseButton == pressedMouseButton
then
if (deferred) then
setOverrides(e)
hs.eventtap.keyStroke({"cmd"}, "[")
return true
end
return false
end
if forwardMouseButton == pressedMouseButton
then
if (deferred) then
setOverrides(e)
hs.eventtap.keyStroke({"cmd"}, "]")
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'])
if backMouseButton == pressedMouseButton or forwardMouseButton == pressedMouseButton
then
deferred = 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')
hs.mouse.absolutePosition(oldmousepos)
return true, {scroll}
else
return false, {}
end
end)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.