Skip to content

Instantly share code, notes, and snippets.

@zhigang1992
Created June 5, 2017 06:16
Show Gist options
  • Save zhigang1992/22e6658496060a95b4d2d384894b6ffb to your computer and use it in GitHub Desktop.
Save zhigang1992/22e6658496060a95b4d2d384894b6ffb to your computer and use it in GitHub Desktop.
myModifierMode = hs.hotkey.modal.new()
function binderToMods(from,to,mods,toMods)
local function f ()
myModifierMode.triggered = true
hs.eventtap.keyStroke(toMods, to, 1000)
end
myModifierMode:bind(mods, from, f, nil, f )
end
function binder(from,to,mods)
binderToMods(from, to, mods, mods)
end
allModifiers = {
{},
{'ctrl'},
{'cmd'},
{'shift'},
{'alt'},
{'ctrl', 'cmd'},
{'ctrl', 'shift'},
{'ctrl', 'alt'},
{'cmd', 'shift'},
{'cmd', 'alt'},
{'shift', 'alt'}
}
function binderAll(from, to)
for _, v in pairs(allModifiers) do
binder(from, to, v)
end
end
myModifiers = {}
for _, v in pairs(allModifiers) do
table.insert(myModifiers, hs.hotkey.bind(v, "f19",
function()
myModifierMode:enter()
myModifierMode.triggered = false
end,
function()
myModifierMode:exit()
if not myModifierMode.triggered then
for _, m in pairs(myModifiers) do
m:disable()
end
hs.eventtap.keyStroke({}, "f19")
for _, m in pairs(myModifiers) do
m:enable()
end
end
end
)
)
end
binderAll('d', 'left')
binderAll('h', 'down')
binderAll('t', 'up')
binderAll('n', 'right')
binderToMods('a', 'a', {}, {'ctrl', 'shift', 'cmd', 'alt'})
binderToMods('c', 'c', {}, {'ctrl', 'shift', 'cmd', 'alt'})
binderToMods('i', 'i', {}, {'ctrl', 'shift', 'cmd', 'alt'})
binderToMods('escape', 'escape', {}, {'ctrl', 'shift', 'cmd', 'alt'})
binder('space', 'padenter')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment