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.hotkey
API doesn't provide functionality to be able to propagate the captured keydown event. Thehs.eventtap
API does, but using it would involve watching for everykeyDown
event.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.filter
API to enable the hotkey binding when entering the application, and disable it when leaving the application, i.e. something like: