【问题标题】:Autohot key variable function not globalAutohotkey 变量函数不是全局的
【发布时间】:2018-12-12 15:57:55
【问题描述】:

我正在尝试创建一个获取坐标、复制该字段并命名一个变量的函数,但该变量似乎是本地的并且不会从函数中转移出来。坐标 (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

【问题讨论】:

    标签: function variables autohotkey


    【解决方案1】:

    从函数的角度来看,参数本质上是一样的 作为局部变量,除非它们被定义为 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      相关资源
      最近更新 更多