using hotkey to map one key combination to another

527 views
Skip to first unread message

steve....@vydia.com

unread,
Sep 19, 2016, 5:58:14 PM9/19/16
to Hammerspoon
Hi, I am coming from Ubuntu/Windows and used to the ctrl+x,c,v for cut copy and paste.  I am already using hammerspoon for some nice window layout stuff.  I would love to be able to map, for example, cmd+v to ctrl+v.  Like hs.hotkey.bind("cmd", 'v', "ctrl", 'v');  But that's not what it expects.  Anyone know of an easy way to to do that?  If not, I guess I'll just stick around long enough to change my muscle memory.

steve....@vydia.com

unread,
Sep 19, 2016, 6:07:32 PM9/19/16
to Hammerspoon, steve....@vydia.com
I found eventtap, and came up with this, thinking it would work:

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

but nope.  any ideas?

Chris Jones

unread,
Sep 19, 2016, 6:22:37 PM9/19/16
to steve....@vydia.com, Hammerspoon
Hey

> On 19 Sep 2016, at 22:58, steve....@vydia.com wrote:
> Hi, I am coming from Ubuntu/Windows and used to the ctrl+x,c,v for cut copy and paste. I am already using hammerspoon for some nice window layout stuff. I would love to be able to map, for example, cmd+v to ctrl+v. Like hs.hotkey.bind("cmd", 'v', "ctrl", 'v'); But that's not what it expects. Anyone know of an easy way to to do that? If not, I guess I'll just stick around long enough to change my muscle memory.

So the first thing to note here is that you're wanting to emit a keyboard event in response to a keyboard event. If you emit the cmd-c while ctrl-c is still held down, the system is going to see cmd-ctrl-c, so we need to emit the event after you've let go of the keyboard. Fortunately, hs.hotkey.bind() can do this with its releasefn argument :)

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

Cheers,
Chris

Reply all
Reply to author
Forward
0 new messages