Error: Hotkey or hotstring is missing its opening brace.

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
filky
Posts: 1
Joined: 18 Nov 2023, 10:04

Error: Hotkey or hotstring is missing its opening brace.

Post by filky » 18 Nov 2023, 10:08

Hi,

I'm trying to write a really basic script in AHK V2 and cannot resolve this error message:

Error: Hotkey or hotstring is missing its opening brace.
Line: 4

The code is this:

Code: Select all

#HotIf WinActive("ahk_class TTOTAL_CMD")

F12::  ; Assigns the script to the F12 key
    Loop 500
    {
        SendInput "{Space}{Down}{Space}{Down}{Down}"
        Sleep 100  ; Waits 100 milliseconds between each iteration
    }
    return

#HotIf  ; Reset the condition
Can anyone help with this and point me to where this is going wrong and why?
[Mod edit: Removed img-tags without a link.]

Thanks
Paul.

gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: Error: Hotkey or hotstring is missing its opening brace.

Post by gregster » 18 Nov 2023, 11:35

Like the message indicates, missing braces are the problem:
https://www.autohotkey.com/docs/v2/v2-changes.htm#hotkey-and-hotstring-labels wrote:Hotkeys and non-autoreplace hotstrings are no longer labels; instead, they (automatically) define a function. For multi-line hotkeys, use braces to enclose the body of the hotkey instead of terminating it with return (which is implied by the ending brace).
See also: Hotkeys (v2)

User avatar
DuckingQuack
Posts: 221
Joined: 20 Jan 2023, 18:20

Re: Error: Hotkey or hotstring is missing its opening brace.

Post by DuckingQuack » 18 Nov 2023, 11:51

Code: Select all

F12:: {     ; <--- This one is missing and is the cause of the error
     Loop {
          Stuff
     }
}              ; <--- This one will need to be added also
Best of Luck,
The Duck

Post Reply

Return to “Ask for Help (v2)”