AutoHotKey - 打开一个网站而不给它焦点

AutoHotKey - Open a website without giving it focus

我刚刚创建了这个脚本,它几乎是完美的(满足我的需要)。我唯一希望能够改进它的是让它在运行时 Google.com,它不会给我 Google Chrome 焦点。如何做到这一点?

#PgDn::
Run https://www.google.com
Sleep 2000
SetControlDelay -1
ControlClick, x1570 y600, Google - Google Chrome,,,, NA
Return

本质上,当我按下 Windows 键 + Page Down 时,它会运行 google chrome (并为其提供焦点)然后等待两秒钟并控制点击页面上的坐标(不移动我的鼠标)。我希望在 Google 获得焦点或移动鼠标的情况下完成整个操作。

可能想要等待它获得焦点,然后立即将其恢复到获得焦点的位置。如果这还不够好,我想您需要一些自定义 Chrome 扩展来执行此操作。

要在 Chrome 窃取后恢复焦点,您可以这样做:

SetControlDelay -1

#PgDn::
    ActiveWindow := WinActive("A") ;store the hwnd of current active window
    Run, https://www.google.com
    WinWaitActive, ahk_exe chrome.exe ;wait for chrome to get focus
    WinActivate, % "ahk_id " ActiveWindow ;restore focus
    ControlClick, x1570 y600, Google - Google Chrome, , , , NA
Return

也移动 SetControlDelay -1 设置在热键之外。
无需每次 运行 热键时都设置它,只需在脚本的 auto-execute section(脚本顶部)中设置一次即可。