If the target key is always different for each application - like you show above - it should be the best way, afaik.
If you want to remap several keys per application, you don't need to wrap them separately, but you could do this:
Code: Select all
#IfWinActive ahk_exe Excel.exe
LAlt::a
F1::b
#If
#IfWinActive ahk_exe Word.exe
LAlt::b
F1::w
#If
If you want to remap a key in the same way (same target key) for several applications, you could instead use
#If and the
WinActive() function:
Code: Select all
#If WinActive("ahk_exe Word.exe") || WinActive("ahk_exe notepad.exe")
LAlt::b
#If