Skip to content

Instantly share code, notes, and snippets.

@justintanner
Created April 6, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justintanner/f31d2ee2ac785401a7d65160087bb995 to your computer and use it in GitHub Desktop.
Save justintanner/f31d2ee2ac785401a7d65160087bb995 to your computer and use it in GitHub Desktop.
Chord keys in Hammerspoon
-- Can Hammerspoon create chord / prefix keys like Emacs?
local ctrlXActive = false
local hotkeyModal = hs.hotkey.modal.new()
function startCtrlX()
ctrlXActive = true
hs.timer.doAfter(1, clearCtrlX)
end
function clearCtrlX()
print('Clearing ctrlXActive flag.')
ctrlXActive = false
end
function forwardOrOpen()
hotkeyModal:exit()
if ctrlXActive then
print('Opening file.')
hs.eventtap.keyStroke('cmd', 'o')
else
print('Moving cursor forward.')
hs.eventtap.keyStroke(nil, 'right')
end
hotkeyModal:enter()
clearCtrlX()
end
hotkeyModal:bind({'ctrl'}, 'x', startCtrlX, nil, nil)
hotkeyModal:bind({'ctrl'}, 'f', forwardOrOpen, nil, nil)
hotkeyModal:enter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment