A "normal"
if-statement needs a
block of brackets (
{ }) to make more than one line conditional (the same applies to a lot of other
control flow statements). That means, in your current code only the line
KeyWait, k gets executed based on the result of the
If-check. The rest of the lines gets executed in any case.
Now, for
hotkeys and
hotstrings, the use of the
#If... directives is preferable instead. They allow to create
context-sensitive hotkeys. But contrary to
If, they work purely postional (and don't need brackets).
So, this is how it could be done:
Code: Select all
#if WinActive("ahk_id 0x10542") ; following hotkeys will be context-sensitive
~LButton & k::
KeyWait, k
Send {Backspace}
Sleep 200
Send {Alt}fhu
return
#If ; end of context-sensitive section
The directive
#IfWinactive would be an alternative.
#If with an
expression is more versatile, but not really needed here (in AHK v2 alpha, it would be obligatory, though).