In order to create a hotkey or hotstring that only triggers when certain windows are active or exist, you can put one or several of the following directives before the hotkey definition:
#IfWinActive [, WinTitle, WinText]
#IfWinExist [, WinTitle, WinText]
#IfWinNotActive [, WinTitle, WinText]
#I...