Apparent syntax error parses correctly but causes a hotkey to be ignored

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fpl9000
Posts: 10
Joined: 30 Aug 2016, 11:42

Apparent syntax error parses correctly but causes a hotkey to be ignored

12 May 2022, 09:26

[Moderator's note: Topic moved from Bug Reports.]

Using 1.1.34.01 on Windows 10 20H2 64-bit Home Edition, I accidentally left an extraneous > character on a line by itself in my script, and it still parsed successfully, but the hotkey immediately below the line with the > character is ignored. See the minimal reproducible test case below.

Oddly, if I remove the 2 #IfWinActive lines around the first hotkey, the 2nd hotkey is not ignored (and the script still parses correctly).

Code: Select all

#IfWinActive ahk_exe notepad.exe
^n::MsgBox OK
#IfWinActive
>
^z::MsgBox Ctrl-Z pressed
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: Apparent syntax error parses correctly but causes a hotkey to be ignored

12 May 2022, 10:37

This is not a bug, but a "Method #1" continuation section. In effect, the line with the > starts with an expression operator (greater-than), so it gets merged into the previous (non-empty) line. The line with the hotkey, although it starts with ^ (bitwise-xor), is correctly detected and parsed as a hotkey as that has higher priority.

In effect your script is equivalent to this:

Code: Select all

#IfWinActive ahk_exe notepad.exe
^n::MsgBox OK
#IfWinActive >

^z::MsgBox Ctrl-Z pressed
Removing the second #IfWinActive will result in this (which I verified by pressing Ctrl+N with Notepad open):

Code: Select all

#IfWinActive ahk_exe notepad.exe
^n::MsgBox OK >

^z::MsgBox Ctrl-Z pressed

Amusingly, the equivalent AutoHotkey v2 script will result in a load time error, probably as a side effect of changes in expression continuation (trailing operators can now qualify for merging the next non-blank line):

Code: Select all

#HotIf WinActive("ahk_exe notepad.exe")
^n::MsgBox "OK"
#HotIf
>
^z::MsgBox "Ctrl-Z pressed"

Code: Select all

---------------------------
*
---------------------------
Error at line 4.

Line Text: > ^z::MsgBox "Ctrl-Z pressed"
Error: Invalid hotkey.

The program will exit.
---------------------------
OK   
---------------------------
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 73 guests