Last active
July 14, 2018 10:37
-
-
Save zzquilt/f39bb858d7d5c954349d3b7edadfbad0 to your computer and use it in GitHub Desktop.
实现 space 加相应的键实现光标移动
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
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