2017-06-04 40 views
-2

我遇到以下代碼有問題。我試圖讓循環保釋,並按下TAB鍵時轉到Setup()函數。但是當我按TAB時什麼都沒有發生,它只是繼續循環,請幫助!AutoIt _IsPressed不要在循環中調用

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 
+2

你能提供[MCVE](http://stackoverflow.com/help/mcve)嗎? –

回答

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.")