Skip to content

Instantly share code, notes, and snippets.

@rjhilgefort
Forked from arbelt/init.lua
Last active May 19, 2017 03:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjhilgefort/07ce5cdd3832083d7e94113d54372b1c to your computer and use it in GitHub Desktop.
Save rjhilgefort/07ce5cdd3832083d7e94113d54372b1c 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