Autohotkey ahk运行pid与Window Spy中显示的不同

Autohotkey ahk运行pid与Window Spy中显示的不同,autohotkey,Autohotkey,我试图从Run命令捕获PID,并使用PID来调整窗口大小。但是没有运气。花了几个小时后,我意识到消息框中显示的PID与通过Spy窗口检查的PID不同。有什么建议吗 Run, "C:\Program Files\Git\git-bash.exe",,, PID ;Sleep, 300 MsgBox, %PID% is the process PID ; --> PID shown here is different from PID inspected via Windo

我试图从Run命令捕获PID,并使用PID来调整窗口大小。但是没有运气。花了几个小时后,我意识到消息框中显示的PID与通过Spy窗口检查的PID不同。有什么建议吗

Run, "C:\Program Files\Git\git-bash.exe",,, PID
;Sleep, 300
MsgBox, %PID% is the process PID ; --> PID shown here is different from PID inspected via Window Spy
WinWait, ahk_pid %PID%
;Sleep, 300
;WinActivate, ahk_pid %PID%
WinMinimize, ahk_pid %PID%
;WinMove, ahk_pid %PID%, ,500, 250, 200, 100
return

这是因为出现的窗口不是来自
git bash.exe
进程。
它来自
mintty.exe
,在运行
gitbash.exe
后,它会在某个地方启动

您可以做的最简单的事情是在启动
git bash.exe
后等待窗口出现,如下所示:

Run, % "C:\Program Files\Git\git-bash.exe"
;sleep a bit because other things from mintty.exe seem to get lauched first as well
Sleep, 1000
WinWait, % "ahk_exe mintty.exe"
;get the hwnd of the last found window (the window we waited for above)
hwnd := WinExist()

;and if you for some reason really need the PID, you can do e.g this to get it
WinGet, pid, PID, % "ahk_id " hwnd
MsgBox, % pid

谢谢你的回答,它成功了。实际上,最初我尝试使用chrome窗口(最后我需要对齐chrome),但我的代码不起作用。然后我发现了一个互联网的例子,就是git-bash.exe。我想让我先用GitBash测试一下代码,如果它能工作,我会翻译成GoogleChrome。我设法修复了代码,但这个奇怪的问题(git bash.exe)让我花了几个小时。我刚刚在以前的代码中尝试了chrome.exe,它成功了。:)