Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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