Created
April 6, 2019 17:14
-
-
Save justintanner/f31d2ee2ac785401a7d65160087bb995 to your computer and use it in GitHub Desktop.
Chord keys in Hammerspoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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