2016-08-18 54 views
0

這是我寫到目前爲止的腳本。它只是部分工作。 我只需要在播放鬧鐘後拍攝電腦的屏幕截圖。當我運行腳本時,它立即拍攝一個屏幕截圖,將其保存在適當的文件名和位置下,並關閉mspaint。然後它將每20秒循環一次並採取另一次。我的時間命令有些問題,我無法弄清楚。我如何閱讀我的語法,它應該留在while循環中,直到Elapsed小於20秒。然後,一旦文件被訪問,退出while循環並繼續向下無限循環。AutoHotkey FileGetTime訪問ScreenShot

Loop { 

    FileGetTime, LastTime, alarm.wav, A 
    Elapsed := A_Now - LastTime 

    while (Elapsed > 20000){ 
     FileGetTime, LastTime, alarm.wav, A 
     Elapsed := A_Now - LastTime 
    } 

    send {PrintScreen} 
    Run, MSPaint 
    WinWaitActive, Untitled - Paint 
    Send ^v 
    Sleep, 50 
    Send ^s 
    Sleep, 50 
    Send c:\Screenshots\ 
    Send %A_Now% 
    Sleep, 100 
    Send {Enter} 
    Sleep, 2000 
    WinClose, ahk_exe MSPaint.exe 


    Sleep, 20000 

} 
+0

獲取文件時間計爲** A ** ccess,我想。嘗試刪除',A' – wOxxOm

+0

不,那個「A」告訴應用程序獲取文件的「A」連接時間。 –

+0

對不起,這並不意味着它會脫落。 :) 如果我刪除「A」它默認爲「M」並抓取文件的修改時間。我無法使用修改的時間,因爲播放文件不會修改它。另外我也檢查過,運行腳本不會影響上次訪問時間。在我關閉腳本後立即在4分鐘前顯示訪問時間。 –

回答

2

我想通了通過把一個

MsgBox %Elapsed% 

while循環中。它計算秒不​​是毫秒。將方程式從20000降至20,現在就起作用。

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
; #Warn ; Enable warnings to assist with detecting common errors. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 

LastTime = 0 

Loop 
{ 

    Elapsed = 30 

    while (Elapsed > 20) 
    { 
     FileGetTime, LastTime, alarm.wav, A 
     Elapsed := A_Now - LastTime 
    } 

    send {PrintScreen} 
    Run, MSPaint 
    WinWaitActive, Untitled - Paint 
    Send ^v 
    Sleep, 50 
    Send ^s 
    Sleep, 200 
    Send c:\Screenshots\%A_Now% 
    Sleep, 100 
    Send {Enter} 
    Sleep, 200 
    WinClose, ahk_exe MSPaint.exe 


    Sleep, 20000 

}