How do I make the keybinding be detected but not intercepted? #3130
-
I have a keybinding on I have tried doing
in the keybinding function, but this causes a useless infinite loop. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you're using the bEventTap = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function(event)
if event:getCharacters() ~= 'b' then return end
-- do stuff here
return false -- don't delete the event
end)
bEventTap:start() |
Beta Was this translation helpful? Give feedback.
-
the other way around is to save the handler of the binding and disable and enable it between the keystroke: (pseudocode) hotkeyHandler = hs.hotkey.bind(modifier, key, message, function()
if something then
-- do things
else
-- do original keystroke
hotkeyHandler:disable()
hs.eventtap.keyStroke(modifier, key)
hotkeyHandler:enable()
end to avoid the infinite loop you need to disable the PS:
|
Beta Was this translation helpful? Give feedback.
If you're using the
hs.hotkey
API to make a key binding, it will override any existing behaviour for that key combination. If you just want to monitor key events, consider usinghs.eventtap.new
instead. This API allows you to choose whether to post the event or not, by returning either true or false from your callback. You can't directly create an event tap for a single key, but you can use something like the following to approximate the behaviour: