Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua

Home Page:http://www.hammerspoon.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: I would like to know if a modal is in the state active

muescha opened this issue · comments

I would like to know if a modal is in the state active

local ks = hs.hotkey.modal.new(
            mod,
            key,
            description);

ks:isActive()
ks.isActive -- call value direct

I can do a workaround like this:

function hotkeybindmodal(mod, key, description, startFn, exitFn)

    local active = false

    local ks = hs.hotkey.modal.new(
            mod,
            key,
            description);

    function ks:entered()
        debugInfo("Start Modal Mode for ".. description)
        startFn()
        active = true
    end
    function ks:exited()
        active = false
        exitFn()
        debugInfo("Exit Modal Mode for ".. description)
    end

    function ks:isActive()
        return active
    end

    return ks
end

and use it:

local ks = hotkeybindmodal(
            mod,
            key,
            description);
ks:enter()
print(ks:isActive())

see:

  • PR #3608: Update hotkey.lua: add isActive