Skip to content

How do I make the keybinding be detected but not intercepted? #3130

Answered by jparoz
NightMachinery asked this question in Q&A
Discussion options

You must be logged in to vote

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 using hs.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:

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()

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by NightMachinery
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants