Last active
July 3, 2017 22:32
-
-
Save mzyy94/20f0cea78187459dffa6d55e94298033 to your computer and use it in GitHub Desktop.
.hammerspoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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