如何使用Autohotkey打开新的Chrome标签页?

时间:2018-12-08 07:40:03

标签: autohotkey

此代码将打开一个新的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

如何使用Autohotkey做同样的事情?

1 个答案:

答案 0 :(得分:3)

在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

https://autohotkey.com/docs/commands/WinGet.htm#PID https://autohotkey.com/docs/commands/Run.htm#Parameters https://autohotkey.com/docs/commands/WinSet.htm#Bottom