Autohotkey 变量函数不是全局的

Autohot key variable function not global

我正在尝试制作一个函数,该函数采用坐标、复制该字段并命名一个变量,但该变量似乎是本地变量并且不会传出该函数。坐标 (x,y) 和延迟似乎工作正常,但 desc 变量总是空白。请帮忙!

newest(x, y, delay, variable)

   {


 sleep, %delay%



    click, %x%,%y%  ;desc machine field
    clipboard =           ; empty the clipboard 
    Loop
    {
        If GetKeyState("F2","P")  ; terminate the loop whenever you want by pressing F2
        break
        Send {Ctrl Down}c{Ctrl Up}
            if  clipboard is not space   
                break  ; Terminate the loop

        }
    variable := clipboard ;
    msgbox %variable%
    return 

   }

^k::

newest(654, 199, 200, desc)

msgbox %desc%

return

From the function's point of view, parameters are essentially the same as local variables unless they are defined as ByRef.

ByRef 使函数的一个参数成为变量的别名,允许函数为该变量分配一个新值。

newest(x, y, delay, ByRef variable){
    sleep, %delay%
    click, %x%,%y%   ; desc machine field
    clipboard =           ; empty the clipboard 
    Loop
    {
        If GetKeyState("F2","P")  ; terminate the loop whenever you want by pressing F2
            break
        Send {Ctrl Down}c{Ctrl Up}
        If  clipboard is not space   
            break  ; Terminate the loop
    }
    variable := clipboard
    msgbox %variable%
    return 
}

^k::
    newest(54, 199, 200, desc)
    msgbox %desc%
return