我将我的 CAPSLOCK 绑定到 F18(karabiner)作为修饰键。我正在尝试模拟 CAPSLOCK+h、j、k、l 来充当 VIM 移动键。一切正常,但重复时存在延迟问题。也就是说,当我按下 CAPSLOCK+h 时它非常慢,它应该模拟重复按下“<-”键,但它非常延迟并且每秒只发送一个。关于为什么会发生这种情况的任何想法?我init.lua
的如下:
-- A global variable for the Hyper Mode
k = hs.hotkey.modal.new({}, "F17")
-- Enter Hyper Mode when F18 (Hyper/Capslock) is pressed
pressedF18 = function()
k.triggered = false
k.modifier = false
k:enter()
trigger_modifier = function()
k.modifier = true
end
-- Only trigger as modifier if held longer than thisj
hs.timer.doAfter(0.35, trigger_modifier)
end
-- Arrow keys
k:bind({}, 'h', function()
hs.eventtap.keyStroke({}, 'Left')
k.triggered = true
end)
k:bind({}, 'j', function()
hs.eventtap.keyStroke({}, 'Down')
k.triggered = true
end)
k:bind({}, 'k', function()
hs.eventtap.keyStroke({}, 'Up')
k.triggered = true
end)
k:bind({}, 'l', function()
hs.eventtap.keyStroke({}, 'Right')
k.triggered = true
end)
-- Leave Hyper Mode when F18 (Hyper/Capslock) is pressed,
-- send ESCAPE if no other keys are pressed.
releasedF18 = function()
k:exit()
if not k.triggered then
-- If hotkey held longer than this amount of time
-- let it remain as modifier and don't send ESCAPE
if not k.modifier then
hs.eventtap.keyStroke({}, 'ESCAPE')
else
print("Modifier detected")
end
end
end
-- Bind the Hyper key
f18 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)