![Autohotkey 监视文件夹中的新文件](https://linux22.com/image/1438045/Autohotkey%20%E7%9B%91%E8%A7%86%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%AD%E7%9A%84%E6%96%B0%E6%96%87%E4%BB%B6.png)
我正在尝试观察文件夹中是否有新的变化,然后执行按键操作。
以下是我目前所掌握的信息:
#j::
Loop 5
{
Send ^!{c}
; watch and wait folder path until a new file is added
Send {down}
}
return
我不确定如何解决这个问题,有什么帮助吗?
答案1
#j::
IfWinActive, ahk_class CabinetWClass
{
SetTitleMatchMode, 3
WinGetTitle, active_title, A
for window in ComObjCreate("Shell.Application").Windows
try address := % window.Document.Folder.Self.Path ; http://ahkscript.org/boards/viewtopic.php?p=28751#p28751
; MsgBox, "%address%"
SetTimer, FileAdded, 500
}
return
FileAdded:
Loop, %address%\*.*
{
now := %A_Now%
EnvSub, now, %A_LoopFileTimeCreated%, seconds
If now < 2 ; newer as 2 seconds
{
SetTimer, FileAdded, off
; MsgBox a new file `n%A_LoopFileFullPath% `nis added in %address%
; Run, %address% ; if the explorer window has been closed in the meantime
WinWait, %active_title%
WinActivate, %active_title%
WinWaitActive, %active_title%
; Send, your keys
; Sleep some time
; SetTimer, FileAdded, on
}
}
return