此代码打开一个新的 chrome 选项卡,并将整个 chrome 窗口放在所有其他正在运行的程序后面:
Browser = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
URL = "http://cyberforum.ru"
Name = Mid(Browser, InStrRev(Browser, "\") + 1)
For Each P In GetObject("winmgmts:\\.\root\CIMV2")._
ExecQuery("Select ParentProcessID from Win32_Process Where Name = '" & Name & "'")
PID = P.ParentProcessID : If InStr(PIDs & " ", " " & PID & " ") Then Exit For
PIDs = PIDs & " " & PID
Next
With CreateObject("WScript.Shell")
Set Exe = .Exec(Browser & " " & URL)
If IsEmpty(PID) Then PID = Exe.ProcessID Else WSH.Sleep 1000
Do : A = .AppActivate(PID) : Loop Until A
.SendKeys "%{Esc}"
End With
Run Code Online (Sandbox Code Playgroud)
我怎样才能用 Autohotkey 做同样的事情?
在 AHK 中,您可以使用变量(例如 chromePID)来存储程序的唯一进程 ID (PID) 并按如下方式处理它:
Browser = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
URL = "http://cyberforum.ru"
IfWinExist ahk_exe chrome.exe
{
WinGet, chromePID, PID, ahk_exe chrome.exe
Run %Browser% "%URL%"
}
else
Run %Browser% "%URL%",,, chromePID
WinWait ahk_pid %chromePID%
WinSet, Bottom,, ahk_pid %chromePID% ; send the window beneath all other windows
return
Run Code Online (Sandbox Code Playgroud)
https://autohotkey.com/docs/commands/WinGet.htm#PID https://autohotkey.com/docs/commands/Run.htm#Parameters https://autohotkey.com/docs/commands/WinSet.htm#底部
| 归档时间: |
|
| 查看次数: |
3429 次 |
| 最近记录: |