Skip to content

Instantly share code, notes, and snippets.

@nickcheng
Last active July 12, 2021 01:13
Show Gist options
  • Save nickcheng/01dc00105bc21bbcd046bcd1957f60b2 to your computer and use it in GitHub Desktop.
Save nickcheng/01dc00105bc21bbcd046bcd1957f60b2 to your computer and use it in GitHub Desktop.

Revisions

  1. nickcheng revised this gist Jul 12, 2021. No changes.
  2. nickcheng created this gist Aug 14, 2019.
    48 changes: 48 additions & 0 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    -- HANDLE SCROLLING

    local deferred = false

    overrideRightMouseDown = hs.eventtap.new({ hs.eventtap.event.types.rightMouseDown }, function(e)
    --print("down"))
    deferred = true
    return true
    end)

    overrideRightMouseUp = hs.eventtap.new({ hs.eventtap.event.types.rightMouseUp }, function(e)
    -- print("up"))
    if (deferred) then
    overrideRightMouseDown:stop()
    overrideRightMouseUp:stop()
    hs.eventtap.rightClick(e:location())
    overrideRightMouseDown:start()
    overrideRightMouseUp:start()
    return true
    end

    return false
    end)


    local oldmousepos = {}
    local scrollmulty = -4 -- negative multiplier makes mouse work like traditional scrollwheel
    local scrollmultx = -1
    dragRightToScroll = hs.eventtap.new({ hs.eventtap.event.types.rightMouseDragged }, function(e)
    -- 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 * scrollmultx, dy * scrollmulty},{},'pixel')

    -- put the mouse back
    hs.mouse.setAbsolutePosition(oldmousepos)

    return true, {scroll}
    end)

    overrideRightMouseDown:start()
    overrideRightMouseUp:start()
    dragRightToScroll:start()