-
Notifications
You must be signed in to change notification settings - Fork 5
/
marble.lua
75 lines (67 loc) · 2.7 KB
/
marble.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- Source:https://github.com/tekezo/Karabiner/issues/814#issuecomment-415388742
-- 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)
-- print("down")
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)
-- print("up")
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'])
-- print ("pressed mouse " .. pressedMouseButton)
if backMouseButton == pressedMouseButton or forwardMouseButton == pressedMouseButton
then
-- print("scroll");
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')
-- put the mouse back
hs.mouse.absolutePosition(oldmousepos)
return true, {scroll}
else
return false, {}
end
end)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()