I'm looking at having a certain hotkey only available in Google Chrome:
hs.hotkey.bind({"cmd"}, "0", function()
if hs.window.focusedWindow():application():name() == 'Google Chrome' then
hs.eventtap.keyStrokes("000000000000000000")
end
end)
The issue with this approach is the hotkey will become un-usable on other apps. E.g. CMD+0 will not trigger the Reset Zoom command in Discord.
How can I prevent that?
The
hs.hotkeyAPI doesn't provide functionality to be able to propagate the captured keydown event. Thehs.eventtapAPI does, but using it would involve watching for everykeyDownevent.I'll point to what is mentioned in a somewhat related GitHub issue:
In other words, for what you're trying to achieve, it's recommended you use the
hs.window.filterAPI to enable the hotkey binding when entering the application, and disable it when leaving the application, i.e. something like: