hs.eventtap.keyStroke with modifier works only after double press

1.1k views Asked by At

I want change copy command from Cmd+c to Ctrl+c. I have this code:

hs.hotkey.bind({"ctrl"}, "c", function()
    hs.eventtap.keyStroke({"cmd"}, "c")
end)

But it works only after two 'c' fast presses with Ctrl button pressed. It's not a Cmd button problem because Shift+c doesn't work as well.

Haw can I remap Cmd+c combination by Hammerspoon?

My system: Mac OSX 10.14 Mojave

2

There are 2 answers

0
ericslaw On

I am using hammerspoon to map ctrl-c and ctrl-v to their respective cmd-c and cmd-v equivalents via:

hs.hotkey.bind({"ctrl"}, "c", nil, function()
    hs.eventtap.keyStroke({"cmd"}, "c")
end)
hs.hotkey.bind({"ctrl"}, "v", nil, function()
    hs.eventtap.keyStroke({"cmd"}, "v")
end)

I can still use the cmd-c and cmd-v keystrokes, but now ctrl-c and ctrl-v also work.

0
mAndroid On

I know this is an old post but I stumbled across it with the same issue. I think what's happening is that the super key is still in action when the event triggers.

I got around it with a delay to allow the user time to have stopped pressing super:

  hs.timer.doAfter(0.3, function()
    hs.eventtap.keyStroke({"cmd"}, "`") 
  end)