Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
12.14k stars 587 forks source link

EventTap stoped after hs.doc.hsdocs.start() #1524

Closed dingmingxin closed 7 years ago

dingmingxin commented 7 years ago

Here is my configuration:

local hk = require "hs.hotkey"
local hyperShift = {'ctrl', 'alt', 'cmd', 'shift'}
function test(e)
        print("scrolled")
end

hs.eventtap.new({hs.eventtap.event.types.scrollWheel}, test):start()

hk.bind(hyperShift, "h", function()
    hs.doc.hsdocs.start()
end

hk.bind(hyperShift, "x", function()
    hs.doc.hsdocs.stop()
end)
  1. Before I start hsdocs server, the scroll callback is called successfully.
  2. After start the docs server without opening browser, the scroll callback was still working
  3. But when I opened http://localhost:12345/ with my default webbrowser, the scroll callback was no longer working
  4. Even if I call hsdocs.stop, the callback was still not working.
  5. Only by reloading the config file can I make the callback work again.

Here is my env:

macos 10.12.5
Hammerspoon 0.9.55

I think something abnormal must happened when http server is access by client. But I can not figure it out, would someone help ?

cmsj commented 7 years ago

I'd start by capturing the return value of the eventtap creation in a variable (not a local), otherwise it's at risk of being garbage collected, which may be what's happening here.

Does that help?

dingmingxin commented 7 years ago

Solved! Many thanks