autohotkey - ahk 运行 pid 与 Window Spy 中显示的不同
问题描述
我正在尝试从运行命令中捕获 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
推荐阅读
- c++ - 我可以在不强制任何/所有模板参数的情况下静态断言实体是模板类的实例化吗?
- arrays - c中的重复单词和指针
- javascript - 如何将过渡效果应用于从带有按钮的数组中获取的文本?
- excel - Excel VBA在For循环中复制行
- r - 使用 lapply 创建一个新的数据框列表,总结网络分析
- django - 如何根据当前的新记录和Django中存在的另一条记录生成新记录?
- excel - vba - 插入公式范围
- sql - PostgreSQL 使用 where 子句的多列输出
- android - 如何从适配器类更改 TextView 文本?
- github-actions - GitHub 动作 | 触发除一个子文件夹外的根文件夹的管道