Skip to content

Commit

Permalink
Add @arbelt's "send escape on short ctrl press" Hammerspoon config
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncodes committed Oct 4, 2016
1 parent df83b7e commit 5a38510
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions freshrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ init_vim() {
fresh bin/\* --bin
fresh bin/wemux/\* --bin

fresh hammerspoon/\*.lua --file=~/.hammerspoon/init.lua

fresh twe4ked/dotfiles bin/heroku-remote-add --bin
fresh pengwynn/dotfiles bin/git-pr --bin
fresh bartman/git-wip git-wip --bin
Expand Down
43 changes: 43 additions & 0 deletions hammerspoon/control_escape.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ctrl_table = {
sends_escape = true,
last_mods = {}
}

control_key_timer = hs.timer.delayed.new(0.15, function()
ctrl_table["send_escape"] = false
-- log.i("timer fired")
-- control_key_timer:stop()
end
)

last_mods = {}

control_handler = function(evt)
local new_mods = evt:getFlags()
if last_mods["ctrl"] == new_mods["ctrl"] then
return false
end
if not last_mods["ctrl"] then
-- log.i("control pressed")
last_mods = new_mods
ctrl_table["send_escape"] = true
-- log.i("starting timer")
control_key_timer:start()
else
-- log.i("contrtol released")
-- log.i(ctrl_table["send_escape"])
if ctrl_table["send_escape"] then
-- log.i("send escape key...")
hs.eventtap.keyStroke({}, "ESCAPE")
end
last_mods = new_mods
control_key_timer:stop()
end
return false
end

control_tap = hs.eventtap.new({12}, control_handler)

control_tap:start()


0 comments on commit 5a38510

Please sign in to comment.