gpt4 book ai didi

lua - 我的 Hammerspoon 脚本中的键重复延迟

转载 作者:行者123 更新时间:2023-12-01 23:29:53 24 4
gpt4 key购买 nike

我将我的 CAPSLOCK 绑定(bind)到 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)

最佳答案

我有一些类似的缓慢。似乎在最新版本之一中引入了一些缓慢。您可以使用 fastKeyStroke 调用较低级别的函数下面的功能。我已经包含了我的 hjkl实现,所以你可以看到它使用。另请注意,我将 5 个参数传递给 hs.hotkey.binddocs 中指定的用于键重复。

local hyper = {"shift", "cmd", "alt", "ctrl"}

local fastKeyStroke = function(modifiers, character)
local event = require("hs.eventtap").event
event.newKeyEvent(modifiers, string.lower(character), true):post()
event.newKeyEvent(modifiers, string.lower(character), false):post()
end

hs.fnutils.each({
-- Movement
{ key='h', mod={}, direction='left'},
{ key='j', mod={}, direction='down'},
{ key='k', mod={}, direction='up'},
{ key='l', mod={}, direction='right'},
{ key='n', mod={'cmd'}, direction='left'}, -- beginning of line
{ key='p', mod={'cmd'}, direction='right'}, -- end of line
{ key='m', mod={'alt'}, direction='left'}, -- back word
{ key='.', mod={'alt'}, direction='right'}, -- forward word
}, function(hotkey)
hs.hotkey.bind(hyper, hotkey.key,
function() fastKeyStroke(hotkey.mod, hotkey.direction) end,
nil,
function() fastKeyStroke(hotkey.mod, hotkey.direction) end
)
end
)

Source关于缓慢

关于lua - 我的 Hammerspoon 脚本中的键重复延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com