You could add a loop to the command you're using to disable hotkeys that uses the "{ACTIVEWINDOWTITLE}" token to check which window has focus, so that the loop stops if it's your target window, and the next action can re-enable hotkeys.
You may want to add a second loop before the first one that waits until the active window is no longer the target window (as otherwise hotkeys would be re-enabled instantly if you execute the command while your target window still has focus).
In addition, you may also want to add a check to the loop that stops the command if hotkeys are re-enabled some other way (E.G. if you click the button on the main window)