首页 > 解决方案 > Autohotkey - 函数参数中的函数名称

问题描述

我在将另一个函数中的参数作为参数传递函数时遇到问题。下面的代码:

MSG(text) {
MsgBox, %text%
return
}

clicker(X1,Y1,X2,Y2,IMGFILE,ErrorLvlTrue,ErrorLvlFalse) {
CoordMode, Mouse, Window
CoordMode, Pixel, Window
sleep 1000
ImageSearch,OutX1,OutY1,%X1%,%Y1%,%X2%,%Y2%,%IMGFILE%
if (ErrorLevel = 0) {
return ErrorLvlTrue
}
else {
return ErrorLvlFalse
}
}

clicker(0,0,1900,1000,"*20 image_file.bmp",MSG(OutX1),MSG(OutY1))

不管它是否找到图像,我都得到了 MSG() 函数调用。

标签: autohotkey

解决方案


Global myCount
clicker(0, 0, 1900, 1000, "*20 image_file.bmp", MSG(OutX1), MSG(OutY1))
Return

MSG(text) 
{
    myCount ++
    MsgBox % ""
    .   "This MSG function is executed earlier " myCount " times" "`n`n" 
    .   "and Your text argument is  -->" text "<--"
}

clicker(X1, Y1, X2, Y2, IMGFILE, ErrorLvlTrue, ErrorLvlFalse) 
{
    If FileExist(IMGFILE)           
        MsgBox % "OK. You have an img file"
    Else
        MsgBox % "Nop. You do not have an img file"
    CoordMode, Mouse, Window
    CoordMode, Pixel, Window
    Sleep, 1000
    ImageSearch, OutX1, OutY1, % X1, % Y1, % X2, % Y2, % IMGFILE
    MsgBox % ""
    .   "Now your clicker function executed" "`n`n"
    .   "X1, Y1  (" X1 ", "Y1 ")`n`n"
    .   "X2, Y2  (" X2 ", "Y2 ")`n`n"
    .   "Image File is  -->" ImgFile "<--`n`n"
    .   "Error Level is  -->" ErrorLevel "<--"    ; "2" means there was a problem
}

推荐阅读