Any way to create a config for remap all cmd to ctrl? #3246
-
I want to remap my cmd to be ctrl in a terminal window only. Is there an easy way to do this with hammerspoon? This is something I was trying but with no success... but it works if I add a key. I want it to be any combination of modifiers and keys. local modal = hs.hotkey.modal.new()
modal:bind({"cmd"}, 'WHAT_TO_PUT_HERE????', nil, function()
hs.eventtap.keyStroke({"ctrl"}, 'WHAT_TO_PUT_HERE????')
end)
hs.window.filter.new('terminal')
:subscribe(hs.window.filter.windowFocused,function()
modal:enter()
end)
:subscribe(hs.window.filter.windowUnfocused,function()
modal:exit()
end) Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
E.g. #3190 (comment) Edit: I didn't post the any code because I haven't done this, and don't have a Mac atm to test the code. However, I can post one if you need one; can't guarantee whether it will work though. |
Beta Was this translation helpful? Give feedback.
-
Notes:
This should work: local eventtap = hs.eventtap
local eventTypes = eventtap.event.types
local keycodes = hs.keycodes.map
local windowFilter = hs.window.filter
local function cmd2CtrlEventHandler(event)
local flags = event:getFlags()
local keycode = event:getKeyCode()
if flags.cmd then
flags.cmd = false
flags.ctrl = true
end
if keycode == keycodes.cmd then
keycode = keycodes.ctrl
elseif keycode == keycodes.rightcmd then
keycode = keycodes.rightctrl
end
event:setKeyCode(keycode)
event:setFlags(flags)
return false
end
local cmd2CtrlEventTapObj = eventtap.new({
eventTypes.flagsChanged,
eventTypes.keyDown,
eventTypes.keyUp
}, cmd2CtrlEventHandler)
TerminalFocusFilter = windowFilter.new('Terminal'):subscribe({
[windowFilter.windowFocused] = function() cmd2CtrlEventTapObj:start() end,
[windowFilter.windowUnfocused] = function() cmd2CtrlEventTapObj:stop() end
}) |
Beta Was this translation helpful? Give feedback.
-
I created the hammerspoon-windows-mode using the method provided by @MuhammedZakir in case anyone needs a starting scripts to mimic keybinding in windows. |
Beta Was this translation helpful? Give feedback.
Notes:
This should work: