【问题标题】:Run a program and then resize the window using AutoHotKey运行程序,然后使用 AutoHotKey 调整窗口大小
【发布时间】:2017-11-24 19:41:24
【问题描述】:

我目前有以下 AutoHotKey 脚本:

Run, "C:\Program Files\Git\git-bash.exe"
WinWait, MINGW64:/
WinActivate
WinMove A, , , , 735, 640

这运行git-bash.exe,等待它完全打开,激活打开的窗口并将其调整为宽度 735 和高度 640。只要我只执行一次它就可以工作。当我第二次运行该脚本时,当 git-bash.exe-window 已经存在时,调整大小不起作用,因为它调整了第一个窗口的大小。如何调整刚刚打开的窗口的大小?

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    运行,目标 [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]

    Run, "C:\Program Files\Git\git-bash.exe",,, PID

    WinWait [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]

    WinWait, ahk_pid %PID%

    WinActivate [, WinTitle, WinText, ExcludeTitle, ExcludeText]

    WinActivate, ahk_pid %PID%

    WinMove, WinTitle, WinText, X, Y [, Width, Height, ExcludeTitle, ExcludeText]

    WinMove, ahk_pid %PID%, , , , 735, 640

    完成的脚本:

    Run, "C:\Program Files\Git\git-bash.exe",,, PID
    WinWait, ahk_pid %PID%
    WinActivate, ahk_pid %PID%
    WinMove, ahk_pid %PID%, , , , 735, 640
    

    【讨论】:

    • 对我不起作用。 git-bash-窗口已打开但未调整大小。我尝试使用“C:Windows\system32\cmd.exe”代替它,它适用于此,所以原因是git-bash.exe。但是为什么它只适用于第一个窗口的我之前的脚本(我在问题中提到的)?
    • 我会调查一下,但这可能是 git-bash 的问题,而不是 AutoHotkey 代码的问题,正如你所说的那样有效。
    【解决方案2】:

    您可以尝试使用Autohotkey命令WinGet, window, ID, A

    这将检索您的 Windows ID

    代码如下所示:

    Run, "C:\Program Files\Git\git-bash.exe"
    WinWaitActive, MINGW64:/
    sleep 250
    WinGet, window, ID, A
    WinMove, ahk_id %window%, , ,735,640
    return
    

    注意:当您第二次运行该脚本时(如果第一个 [git-bash.exe] 窗口已经存在),您将需要命令行 sleep 250

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 2013-09-18
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多