简体   繁体   中英

Call to nonexistent function AHKv2

I am trying to create a simple InputBox pop-up that asks for an hour:minute combo, and then starts a countdown timer. When the timer reaches zero, it activates a window and then sends input into that window. I have followed the documentation and am still met with the same error over and over Call to nonexistent function . My script used to be far more complicated, but in an effort to troubleshoot, it has gotten progressively simpler and simpler... and now it basically mirrors the documentation -- and yet, I still get this error. Fresh eyes on this would be greatly appreciated!

:*:obstimer::
;; Show the input box
USER_INPUT := InputBox("This is the prompt","This is the title",W200 H300 T30,"").value

;; Split the input time into hours and minutes
TimeArray := StrSplit(USER_INPUT, ":")
hours := TimeArray[1] ; Get the hours part
minutes := TimeArray[2] ; Get the minutes part

;; Convert the hours and minutes to seconds
loop_timer = (hours * 3600) + (minutes * 60)

;; Set a timer that will trigger the press_backtick function every 1000 milliseconds (1 second)
SetTimer, press_backtick, 1000

return

press_backtick:
    loop_timer-- ; Decrement the loop timer by 1
    if (loop_timer <= 0) { ; If the loop timer is less than or equal to 0
        WinActivate, ahk_exe obs64.exe ; Activate the obs64.exe window
        ControlSend, , {U+0060}, ahk_exe obs64.exe ; Send the backtick character ` to the obs64.exe window
        SetTimer, press_backtick, off ; Turn off the timer
    }
return

Your syntax is so far from being valid AHKv2 syntax, that the AHK script launcher deduces your script as being AHKv1, and therefore you get the error for a non existent function. (A function InputBox doesn't exist in AHKv1, it's a legacy command there)

Here's the script in AHKv2 syntax, there are loads of changes, and you also had some errors which wouldn't have worked even in v1.
I'd recommend you to go through v2 changes before trying to write v2 code (assuming you have a v1 background). Or if this is your first time writing AHK, be sure to look at v2 examples and documentations.

:*:obstimer::
{
    global loop_timer
    
    USER_INPUT := InputBox("This is the prompt", "This is the title", "W200 H300 T30", "").value

    TimeArray := StrSplit(USER_INPUT, ":")
    hours := TimeArray[1] 
    minutes := TimeArray[2] 

    loop_timer := (hours * 3600) + (minutes * 60)

    SetTimer(press_backtick, 1000)
}

press_backtick()
{
    global loop_timer
    loop_timer-- ; Decrement the loop timer by 1
    if (loop_timer <= 0) { 
        WinActivate("ahk_exe obs64.exe") 
        ControlSend("{U+0060}", , "ahk_exe obs64.exe") 
        SetTimer(press_backtick, 0)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM