Skip to content

Instantly share code, notes, and snippets.

@ianchen06
Created February 4, 2017 14:50
Show Gist options
  • Save ianchen06/bc4746694f92c1d2bcf01906df2274a4 to your computer and use it in GitHub Desktop.
Save ianchen06/bc4746694f92c1d2bcf01906df2274a4 to your computer and use it in GitHub Desktop.
init.lua file for hammerspoon
send_escape = false
last_mods = {}
control_key_handler = function()
send_escape = false
end
control_key_timer = hs.timer.delayed.new(0.15, control_key_handler)
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
last_mods = new_mods
send_escape = true
control_key_timer:start()
else
last_mods = new_mods
control_key_timer:stop()
if send_escape then
return true, {
hs.eventtap.event.newKeyEvent({}, 'escape', true),
hs.eventtap.event.newKeyEvent({}, 'escape', false),
}
end
end
return false
end
control_tap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, control_handler)
control_tap:start()
other_handler = function(evt)
send_escape = false
return false
end
other_tap = hs.eventtap.new({hs.eventtap.event.types.keyDown}, other_handler)
other_tap:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment