Skip to content

Instantly share code, notes, and snippets.

@zzquilt
Last active July 14, 2018 10:37
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 zzquilt/f39bb858d7d5c954349d3b7edadfbad0 to your computer and use it in GitHub Desktop.
Save zzquilt/f39bb858d7d5c954349d3b7edadfbad0 to your computer and use it in GitHub Desktop.
实现 space 加相应的键实现光标移动
keys={j="down",k="up",h="left",l="right",u="home",i="end",n="pagedown",m="pageup"}
hotkeys={}
anyKeyPressed=false
for key,val in pairs(keys)do -- Table iteration.
hotkeys[key]=hs.hotkey.new(nil, key,
function ( )
hs.eventtap.keyStroke(nil , val,1000)
anyKeyPressed=true
end, nil, function ( )
hs.eventtap.keyStroke(nil , val,1000)
anyKeyPressed=true
end)
hotkeys["shift" .. key] = hs.hotkey.new("shift", key,
function ( )
hs.eventtap.keyStroke("shift" , val,1000)
anyKeyPressed=true
end, nil, function ( )
hs.eventtap.keyStroke("shift" , val,1000)
anyKeyPressed=true
end)
end
for key,val in pairs(hotkeys)do -- Table iteration.
print(key,val)
end
spaceHotKey=hs.hotkey.new(nil, "space",
function ( )
for key,val in pairs(hotkeys)do -- Table iteration.
print("enable")
val:enable()
end
end ,function ( )
for key,val in pairs(hotkeys)do -- Table iteration.
print("disable")
val:disable()
end
if not anyKeyPressed then
spaceHotKey:disable()
hs.eventtap.keyStroke(nil , "space" ,1000)
spaceHotKey:enable()
end
anyKeyPressed=false
end,nil)
spaceHotKey:enable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment