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]
#IfWinNotExist [, WinTitle, WinText]
Example: You want stackoverflow.com
to be sent whenever you type so
(and a whitespace after that) in Google Chrome, but ignore the hotstring in any other window.
#IfWinActive, ahk_class Chrome_WidgetWin_1
::so::stackoverflow.com
By using #If [, Expression ]
, you can make a hotkey trigger only when an arbitrary expression is true, for example:
#If A_Hour < 9
F1::
MsgBox, It is too early to ask for help!
return