2

I'm coming from using Linux or Windows.

For example, I'm trying to allow myself to use cmd+c or ctrl+c to copy text in macOS. This is the Hammerspoon script I have, but it doesn't seem to be working:

-- Create an event tap for keyDown and keyUp events
controlToCommandTap = hs.eventtap.new(
    {hs.eventtap.event.types.keyDown, hs.eventtap.event.types.keyUp},
    function(evt)
        -- Get the frontmost application
        local frontmostApp = hs.application.frontmostApplication()
    -- If Terminal is frontmost, do not modify the event
    if frontmostApp and frontmostApp:name() == "Terminal" then
        return false
    end

    local flags = evt:getFlags()

    -- If the event includes the Control key, transform it into a Command key press
    if flags.ctrl then
        flags.ctrl = nil    -- remove ctrl flag
        flags.cmd = true    -- add cmd flag
        evt:setFlags(flags)

        -- Suppress the original event and return the modified one
        return true, {evt}
    end

    return false
end

)

Giacomo1968
  • 58,727
Eric Nelson
  • 161
  • 3

1 Answers1

1

I was missing this at the end of the Lua script.

…
        return false
    end
)
controlToCommandTap:start()

Now it works well and both ctl and cmd hotkeys work!

Giacomo1968
  • 58,727
Eric Nelson
  • 161
  • 3