微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ahk run pid 与 Window Spy 中显示的不同

如何解决ahk run pid 与 Window Spy 中显示的不同

我正在尝试从 Run 命令捕获 PID 并使用 PID 来调整窗口大小。但没有运气。花了几个小时后,我意识到消息框中显示的 PID 与通过 Spy Window 检查的 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,它会在您运行 git-bash.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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。