AutoIt _IsPressed没有循环唤醒

时间:2017-06-04 23:08:20

标签: autoit

我遇到以下代码时遇到问题。我试图让循环保释,如果按下TAB键,则转到Setup()函数。但是当我按TAB没有任何反应时,它只是继续循环,请帮忙!

While -1
    While -1
        WinActivate($PID)
        Sleep(1000)
        Send("Hello")
        $timer = TimerInit()
        While -1
            PixelSearch($searchL,$searchT,$searchR,$searchB,"0x" & Hex($color,6),10,1)
--->        If _IsPressed("09",$dll) Then ExitLoop 3 ;HERE IS THE CODE THAT IS NOT WORKING
            If @error <> 1 Then ExitLoop
            If TimerDiff($timer) > 1000 Then
                Sleep(1000)
                WinActivate($PID)
                ExitLoop 2
            EndIf
        Wend
        $timer = TimerInit()
        MouseMove($shade[0], $shade[1])
        While -1
            PixelSearch($shade[0]-10,$shade[1]-10,$shade[0]+10,$shade[1]+10,"0x" & Hex($color,6),10,1)
--->        If _IsPressed("09",$dll) Then ExitLoop 3 ;HERE IS THE CODE THAT IS NOT WORKING
            If @error = 1 Then ExitLoop
            If TimerDiff($timer) > 5000 Then
                Sleep(1000)
                WinActivate($PID)
                Exitloop 2
            EndIf
         Wend
    Wend
 Wend
Setup()
EndFunc

1 个答案:

答案 0 :(得分:0)

我假设你遇到了$dll变量的问题。它可能没有初始化。摆脱它。这个小例子很好用:

#include <Misc.au3>

MsgBox( 0, "1 loop", "Now testing with 1 loop." )
While -1
    If _IsPressed("09") Then
        MsgBox( 0, "_IsPressed", "You pressed the TAB key." )
        ExitLoop
    EndIf
WEnd

MsgBox( 0, "3 loops", "Now testing with 3 loops." )
While -1
    While -1
        While -1
            If _IsPressed("09") Then
                MsgBox( 0, "_IsPressed", "You pressed the TAB key." )
                ExitLoop 3
            EndIf
        WEnd
    WEnd
WEnd

MsgBox( 0, "_IsPressed", "Test done." )