Open ColinLondon opened 5 years ago
For this kind of low level input modification I generally encourage people to use Karabiner Elements - it runs in the kernel so it can modify the input events much earlier.
THX
I can get the modifier working with the code segment below. But that also modifies the driver behaviour. What I'd like is to just have the modifier key, but applied to the driver behaviour (if I am explaining that clearly!).
Here's the code I have:
`local oldmousepos = {} -- local scrollmultY = -4 -- negative multiplier makes mouse work like traditional scrollwheel local scrollmultY = 6 -- positive multiplier makes mouse work like Magic Nouse local scrollmultX = -12 -- separate var for horizontal scrolling
mousetap = hs.eventtap.new({5}, function(e) oldmousepos = hs.mouse.getAbsolutePosition() local mods = hs.eventtap.checkKeyboardModifiers() -- if mods['shift'] then -- modifier if mods['ctrl'] then -- modifier -- print ("will scroll") 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 scrollmultX, dy scrollmultY},{},'pixel') scroll:post()
-- put the mouse back
hs.mouse.setAbsolutePosition(oldmousepos)
-- return true, {scroll}
return true
else
return false, {}
end
-- print ("Mouse moved!")
-- print (dx)
-- print (dy)
end) mousetap:start() `
I have a Kensington Expert Mouse with ball and scroll wheel.
I only need Hammerspoon to detect a modifier key (e.g. Ctrl) to turn the ball into scroll control when the modifier is held down (otherwise the default of moving the cursor).
I cannot get this to work without changing the mouse driver behaviour (acceleration, etc.).
Any ideas? THX