OSX High Sierra でHammerspoonを使って「真ん中ボタン+マウスホイール」をブラウザ等のスクロールにする

Karabinerが使えないので Hammer Spoon で作られた方がいらっしゃいます。 なんと便利 !

-- local log = hs.logger.new("my_logger","debug")
curr_win = nil
mx = 100
my = 100
function get_window_under_mouse()
    local _ = hs.application

    local my_pos = hs.geometry.new(hs.mouse.getAbsolutePosition())
    local my_screen = hs.mouse.getCurrentScreen()

    return hs.fnutils.find(hs.window.orderedWindows(), function(w)
        return my_screen == w:screen() and my_pos:inside(w:frame())
    end)
end
down_event = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e)
    curr_win = get_window_under_mouse()

    local mp = hs.mouse.getAbsolutePosition();
    mx = mp["x"]
    my = mp["y"]
    return true
end)
down_event:start()
release_event = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e)
    curr_win = nil
    return true
end)
release_event:start()
drag_event = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDragged }, function(e)
    if (curr_win) then
    local dx = e:getProperty(hs.eventtap.event.properties.mouseEventDeltaX)
    local dy = e:getProperty(hs.eventtap.event.properties.mouseEventDeltaY)

    hs.eventtap.scrollWheel({dx * 3, dy * 4}, {}, "pixel")
    hs.mouse.setAbsolutePosition({x = mx, y = my})
    end
    return true
end)
drag_event:start()

引用 : https://goo.gl/Aqs2j8
Hammerspoon docs: hs.eventtap.event


No.191
06/17 22:19

edit