2017-05-24 17 views
1

While 루프 및 일부 기능을 포함하는 AutoIt 스크립트를 일시 중지하고 싶습니다. 그러나 나는 HotKeySet()에서만 원본을 닫을 수있다. 어떻게 일시 중지 할 수 있습니까?일시 중지 while 단축키로 루프

스크립트는 화면의 일부 (x, y 좌표가 구성 파일에 설정되어 있음)의 변경 사항을 확인하고 경고 사운드를 재생 한 후 스크린 샷을 캡처합니다. 일시 중지 버튼을 누를 때 While 루프가 중지되지 않습니다. 그러나 프로그램을 닫으면 작동합니다. 나는 while1 루프 일부 기능 내용을 포함하는 AutoIt이 스크립트를 일시 정지 할

Global $Paused, $counter = 0 
HotKeySet("{1}", "TogglePause") 
HotKeySet("{2}", "Terminate") 
HotKeySet("{3}", "ShowMessage")  

Init() 
Start() 
While 1 
    $counter +=1 
    ToolTip('Script is "Running"',0,0, $counter, 1) 
    Sleep(700) 
     Switch TrayGetMsg() 
     Case $resume 
     Start() 
     DisableAlert() 
     Case $exit 
     ExitLoop 
     Exit 
    EndSwitch 
WEnd  

//some of the functions  
Func Start() 
    $ready = 0 
    $count = 0 
    $lastScreenshotNum = 0 
    TrayItemSetState($resume, $TRAY_DISABLE) 
    TraySetIcon("on.ico") 
    TakeScreenshot() 
    AdlibRegister(TakeScreenshot,2000) 
EndFunc  

Func Stop() 
    AdlibUnRegister(TakeScreenshot) 
    TraySetIcon("off.ico") 
    TrayItemSetState($resume, $TRAY_ENABLE) 
EndFunc 

Func TogglePause() 
    Stop() 
    $Paused = NOT $Paused 
    While $Paused 
     sleep(100) 
     ToolTip('Script is "Paused"',0,0, $counter, 1) 
    WEnd 
    ToolTip("") 
EndFunc 

Func Terminate() 
    Exit 0 
EndFunc 

Func ShowMessage() 
    MsgBox(4096,"","This is a message.") 
EndFunc 

Func EnableAlert() 
    SendMail() 
    Alert() 
    AdlibRegister(Alert,5000) 
EndFunc 

Func DisableAlert() 
    AdlibUnRegister(Alert) 
EndFunc 

Func Alert() 
    SoundPlay("alert.mp3") 
EndFunc 
+1

귀하의 TogglePause 기능은 스크린 샷을 일시 정지하지 않습니다,하지만 당신은 다시 전환 싶어요. NOT $ Paused이면 TogglePause의 끝에서 Start()를 추가하십시오. 그것은 작동합니다. – Milos

답변

1

: 여기 내 코드입니다. 하지만 HotKeySet에서 스크립트를 닫을 수만 있습니다. 어떻게 멈출 수 있습니까?

(오류가 확인되지 검증되지 않은) (키 - 전환) 상태 조건부 감독의 지시를 실행하여 While -loops을 "일시 정지"

Global Const $g_sKeyQuit = 'q' 
Global Const $g_sKeyPause = 'p' 
Global Const $g_iDelay  = 500 

Global  $g_bStateQuit = False 
Global  $g_bStatePause = False 

Main() 

Func Main() 

    HotKeySet($g_sKeyQuit, 'SwitchStateQuit') 
    HotKeySet($g_sKeyPause, 'SwitchStatePause') 

    While Not $g_bStateQuit 

     If Not $g_bStatePause Then 

      YourCode() 

     EndIf 

     Sleep($g_iDelay) 

    WEnd 

    Exit 

EndFunc 

Func YourCode() 
    Local Static $iCount = 0 

    $iCount += 1 

    ConsoleWrite($iCount & @LF) 

EndFunc 

Func SwitchStateQuit() 

    $g_bStateQuit = True 

EndFunc 

Func SwitchStatePause() 

    _SwitchVar($g_sKeyPause) 

EndFunc 

Func _SwitchVar(ByRef $bSwitch) 

    $bSwitch = Not $bSwitch 

EndFunc 
  • P 일시 정지합니다.
  • 종료.
  • 필요에 따라 YourCode()의 내용을 변경하십시오. (Main()While -loop을 나타내는)

카메라 설명 :

Conditional While-loop

  • 루프 AdlibRegister()는 (어느 하나를 선택)이를 수행하는 다른 방법이다. 단순히 Sleep()를 추가하는 시간 표류를 소개하기 때문에 정확하게 시간 초과 반복이 필요 경우
  • 사용 TimerDiff()은 (AdlibRegister()도 마찬가지입니다 실행 시간을 무시). As per documentation :

    다른 실행중인 프로세스는 종종 타이밍 정확도에 영향을 미치므로 일시 중지는 요청한 시간보다 약간 더 오래 지속될 수 있습니다.