Skip to content

Cycle through three different actions with consecutive keypresses #3507

Answered by muescha
fooness asked this question in Q&A
Discussion options

You must be logged in to vote

you can do this with a helper:

function hotkeybindcycle(modifier, key, message, callbackMap)
    local currentIndex = 1
    local maxIndex = #callbackMap
    local hotkeyHandler
    hotkeyHandler = hs.hotkey.bind(modifier, key, message, function()
        callbackMap[currentIndex]()
        currentIndex = (currentIndex % maxIndex) + 1
    end)
end

source: https://github.com/muescha/dot_hammerspoon/blob/master/Helpers/HotkeyBindCycle.lua

require("Helpers.HotkeyBindCycle")

fileInfo()

hotkeybindcycle(hyper, "v", keyInfo("Cycle abc"), {
    function() print("a") end,
    function() print("b") end,
    function() print("c") end,
})

hotkeybindcycle(hyper, "b", keyInfo("Cycle defg"), {
    fu…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by fooness
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants