【问题标题】:Wait for previous process to finish before starting new one等待上一个过程完成,然后再开始新的过程
【发布时间】:2016-08-17 11:38:18
【问题描述】:

我需要在 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

【问题讨论】:

  • 这是什么语言?它肯定不是 Python。
  • AutoHotKey (AHK)。但它被 Python 中的 subprocess 模块调用。我链接了 Python,因为我不知道 Python 中是否有一些东西可以和 AHK 一样使用

标签: subprocess autohotkey


【解决方案1】:

你有:

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.

您可能还必须使用窗口检查器来获取窗口/应用程序/进程名称的真实名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 2013-06-15
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    相关资源
    最近更新 更多