我需要在AHK中找到一种等待程序完成的方法,然后再开始新程序。
基本上,我有一个打开应用程序并输入一些参数的脚本。然后,应用程序将花费未知的时间来处理输入数据。
不幸的是,目前ahk脚本在应用程序处理完毕之前结束,此时再次运行相同的ahk脚本并且不会中断先前的处理。
编辑(使用Python中的子进程调用调用ahk .exe)
有没有办法或任何方法来帮助解决这个问题?
供参考,脚本:
#NoEnv
CoordMode, Mouse, Window
SendInput Mode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
if 0 < 2 ; The left side of a non-expression if-statement is always the name of a variable.
{
MsgBox, This script requires 2 incoming parameters but it only received %0%.
ExitApp
}
IfWinNotExist, ahk_exe photoscan.exe
{
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
}
sleep, 200
WinActivate, ahk_exe photoscan.exe
sleep,5
WinMaximize, ahk_exe photoscan.exe
;Macro5:
Click, 476, 438, 0
SendInput {LControl Down}
SendInput {r}
Click, -56, 157, 0
WinActivate, Run Python Script ahk_class QWidget
sleep, 400
SendInput {LControl Up}
SendInput {LControl Down}
SendInput {a}
SendInput {LControl Up}
sleep, 400
SendInput {Backspace}
SendInput %1% ; 1st argument is the photoScan API scriptimages folder directory
SendInput {Tab}
SendInput {Tab}
sleep, 400
SendInput {LControl Down}
SendInput {a} ; 2nd argument is additional args (in our case, the projectName)
SendInput {LControl Up}
SendInput {Backspace}
SendInput %2% ; 2nd argument is the images folder directory & name of output log, model and texture
Sleep, 703
SendInput {Enter}
Click, 476, 438, 0
Return
答案 0 :(得分:0)
你有:
IfWinNotExist, ahk_exe photoscan.exe
{
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
}
sleep, 200
如果应用程序未运行,则设置为启动/启动应用程序。然后睡觉让它加载十分之二秒(这可能太小了)。
在此链接中找到“WinWait”或“WinWaitActive”,而不仅仅是“睡眠”: https://autohotkey.com/docs/commands/WinWaitActive.htm
喜欢这个样本:
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
WinWaitActive, ahk_exe photoscan.exe, , 2
if ErrorLevel
{
MsgBox, WinWait timed out.
return
}
else
WinMinimize ; minimize the window found by WinWaitActive.
您可能还必须使用窗口检查器来获取窗口/应用程序/进程名称的真实名称。