Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active July 3, 2017 22:32
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 mzyy94/20f0cea78187459dffa6d55e94298033 to your computer and use it in GitHub Desktop.
Save mzyy94/20f0cea78187459dffa6d55e94298033 to your computer and use it in GitHub Desktop.
.hammerspoon
local RShift = 0x3c
local RAlt = 0x3d
local RCtrl = 0x3e
local pending
local modKeyRemap = {}
----------
local function pressFn(mods, key)
return function() hs.eventtap.keyStroke(mods, key, 1000) end
end
local function remap(mods, key, pressFn, keyCode)
if key ~= nil then
hs.hotkey.bind(mods, key, pressFn, nil, pressFn)
else
table.insert(modKeyRemap, {
mods = mods,
pressFn = pressFn,
keyCode = keyCode
})
end
end
eventtap = hs.eventtap.new({
hs.eventtap.event.types.flagsChanged,
hs.eventtap.event.types.keyUp,
hs.eventtap.event.types.keyDown
}, function(e)
if e:getType() == hs.eventtap.event.types.flagsChanged then
local keyCode = e:getKeyCode()
local flags = e:getFlags()
for _, map in pairs(modKeyRemap) do
local keyUpMods = {table.unpack(map.mods)}
table.remove(keyUpMods, 1)
if flags:containExactly(keyUpMods) and pending == map.mods then
map.pressFn()
pending = nil
elseif flags:containExactly(map.mods) and keyCode == map.keyCode then
pending = map.mods
end
end
else
pending = nil
end
end)
eventtap:start()
----------
remap({'cmd', 'shift', 'alt'}, nil, pressFn({'ctrl'}, 'up'), RAlt) -- Action Center
remap({'cmd', 'ctrl'}, nil, pressFn({}, 'f11'), RCtrl) -- Connect
remap({'cmd', 'shift'}, nil, pressFn({'cmd'}, 'space'), RShift) -- Spotlight
-- remap({'cmd'}, 'd', pressFn({}, 'f11'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment