问题描述
我最想做的事情是在Office(Word)中实现类似Emacs的按键绑定,经过大量研究,使用Hamperspoon似乎很容易。
https://qiita.com/swdyh/items/04f7da8c1209a067add5 (日文网站)
我检查了这个网站和这个原始引用的网站,并设置了如下初始配置(LUA语言,在init.lua中)。
我的问题是下面的代码做了我想要它做的大部分事情,但最后的 Ctrl-k 说 但是,最后一行代码 Ctrl-k 不允许我删除光标并将删除的数据复制到剪贴板。 好像是keyCode
('e',{'shift','ctrl'})()
不工作。
任何解决方案或建议将不胜感激! 提前致谢。
local function keyCode(key,modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers,string.lower(key),true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers,false):post()
end
end
local function remapKey(modifiers,key,keyCode)
hs.hotkey.bind(modifiers,keyCode,nil,keyCode)
end
local function disableAllHotkeys()
for k,v in pairs(hs.hotkey.getHotkeys()) do
v['_hk']:disable()
end
end
local function enableAllHotkeys()
for k,v in pairs(hs.hotkey.getHotkeys()) do
v['_hk']:enable()
end
end
local function handleGlobalAppEvent(name,event,app)
if event == hs.application.watcher.activated then
-- hs.alert.show(name)
if name ~= "iTerm2" then
enableAllHotkeys()
else
disableAllHotkeys()
end
end
end
appsWatcher = hs.application.watcher.new(handleGlobalAppEvent)
appsWatcher:start()
-- cursor movement
remapKey({'ctrl'},'f',keyCode('right'))
remapKey({'ctrl'},'b',keyCode('left'))
remapKey({'ctrl'},'n',keyCode('down'))
remapKey({'ctrl'},'p',keyCode('up'))
-- Text Editing
remapKey({'ctrl'},'w',keyCode('x',{'cmd'}))
remapKey({'ctrl'},'y',keyCode('v',{'cmd'}))
-- Command
remapKey({'ctrl'},'s',keyCode('f','/',keyCode('z','g',keyCode('escape'))
-- Page scroll
remapKey({'ctrl'},'v',keyCode('pagedown'))
remapKey({'alt'},keyCode('pageup'))
remapKey({'cmd','shift'},',keyCode('home'))
remapKey({'cmd','.',keyCode('end'))
-- Delete the area after the cursor and copy it to the clipboard.
local function keyCtrlK()
keyCode('e','ctrl'})()
keyCode('x',{'cmd'})()
end
hs.hotkey.bind({'ctrl'},'k',keyCtrlK,keyCtrlK)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)