Recently I was asked if there’s a way to get PTFB Pro to run a macro (or a single press item) whenever the target window becomes active. This can indeed be done using a little oft-ignored setting on the “Identifying the Target” page of the macro’s properties:
The key is to tick the “Fire only if foreground window” option; with this set, the macro will only run automatically if the target window is active, ie. the foreground window. Whenever the window becomes inactive (because you’re working in another window) it will fall off PTFB’s radar, but when the window becomes active again PTFB will see it and launch the macro according to the other settings you’ve made on the “Triggers” page.
In the above example you can see I’m using this technique with a Window Restore macro for the Opera browser; I have it set to correctly maximize Opera whenever it becomes the foreground app. There are a few other things to note about this example. Firstly, like other browsers Opera changes its window title according to the web page currently being viewed; to make my macro match Opera regardless of the page I’m viewing, I’ve set it to match any window whose title ends with ” – Opera”. I’ve also specified that only windows that are owned by the Opera process (“opera .exe”) are to be considered a match – this latter setting makes it easier and faster for PTFB Pro to identify genuine Opera windows.