Skip to content

Instantly share code, notes, and snippets.

@jamesgecko
Forked from rjhilgefort/init.lua
Created November 1, 2016 18:16
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 jamesgecko/682eef53fa13c54fec09c64952fc4833 to your computer and use it in GitHub Desktop.
Save jamesgecko/682eef53fa13c54fec09c64952fc4833 to your computer and use it in GitHub Desktop.
Hammerspoon config to send escape on short ctrl press
local sendEscape = true
local ctrlKeyTimer = hs.timer.delayed.new(0.15, function()
sendEscape = false
end)
local lastMods = {}
local flagsChangedHandler = function(event)
local newMods = event:getFlags()
if lastMods.ctrl == newMods.ctrl then return false end
if not lastMods.ctrl then
sendEscape = true
lastMods = newMods
ctrlKeyTimer:start()
else
if sendEscape then hs.eventtap.keyStroke({}, "escape") end
lastMods = newMods
ctrlKeyTimer:stop()
end
return false
end
flagsChanged = hs.eventtap.new({ hs.eventtap.event.types.flagsChanged }, flagsChangedHandler)
flagsChanged:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment