J'ai mon CAPSLOCK lié à F18 (mousqueton) pour agir comme une touche de modification. J'essaye de simuler CAPSLOCK + h, j, k, l pour agir comme des touches de mouvement VIM. Tout fonctionne mais il y a un problème avec le retard en répétant. C'est-à-dire, c'est très lent quand j'appuie sur le CAPSLOCK + h qui devrait simuler en appuyant sur la touche "< -" à plusieurs reprises mais c'est très retardé et n'en envoie qu'un par seconde. Des idées sur pourquoi ça se passe? Mon init.lua
est ci-dessous:Les répétitions de touches sont retardées dans mon script Hammerspoon
-- 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)
Eh oui, c'est la bonne réponse pour l'instant - hs.eventtap.keyStroke() est vraiment la même paire newKeyEvent(), avec un hs.timer.usleep() entre. Nous avons ajouté le bref sommeil pour essayer d'éviter les événements clés qui arrivent en panne. La prochaine version va ajouter un délai configurable, donc vous pouvez l'éteindre si vous voulez :) –
Excellent, merci pour l'info @ ChrisJones –