Autohotkey 自动热键移动chrome窗口

Autohotkey 自动热键移动chrome窗口,autohotkey,Autohotkey,当按下快捷键时,我想在4个不同的窗口中打开4个不同的chrome链接。然后,它应该调整4个窗口的大小,以便一个窗口位于左上角、一个窗口位于右上角、一个窗口位于左下角和一个窗口位于右下角。有人知道我是怎么做到的吗 我试过这个测试代码(底部的示例1),它应该打开一个新的chrome选项卡,调整它的大小并将它移动到右上角,但是它调整了它的大小并将它移动到右上角,距离大约为50像素,所有其他最大化的ChromeTab也会打开,因为if语句对所有ChromeTab都有效 有人知道我如何解决这个问题吗 例1

当按下快捷键时,我想在4个不同的窗口中打开4个不同的chrome链接。然后,它应该调整4个窗口的大小,以便一个窗口位于左上角、一个窗口位于右上角、一个窗口位于左下角和一个窗口位于右下角。有人知道我是怎么做到的吗

我试过这个测试代码(底部的示例1),它应该打开一个新的chrome选项卡,调整它的大小并将它移动到右上角,但是它调整了它的大小并将它移动到右上角,距离大约为50像素,所有其他最大化的ChromeTab也会打开,因为if语句对所有ChromeTab都有效

有人知道我如何解决这个问题吗

例1

Run, chrome.exe
WinGet, WinStatus, MinMax, ahk_exe chrome.exe
if (WinStatus != 0)
    WinRestore, ahk_exe chrome.exe
WinMove, ahk_exe chrome.exe,, 0, 0,

我使用Windows方向箭头快捷方式正确地使窗口捕捉到角落,因为正如您所指出的,WinMove在这方面有点缺陷

此外,我发现如果在重新排列窗口之前先打开所有窗口(我使用hwnd/ahk_id在打开后跟踪每个窗口),那么窗口的定位更容易、更可靠

最后,通过修改,我能够在一个新窗口中使用如下命令打开一个带有指定URL的新chrome选项卡

RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.example.com/"

最后脚本:

RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.google.com/"
topLeft:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.example.com/"
topRight:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.npr.org/"
bottomRight:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.bing.com/"
bottomLeft:=WinExist("A")


;https://stackoverflow.com/questions/23160472/open-chrome-in-windows-from-the-command-line-in-a-new-window
WinActivate, ahk_id %topLeft%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Left}{Up}{Lwin up}
Send {Esc}
Sleep 1000

WinActivate, ahk_id %topRight%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Right}{Up}{Lwin up}
Send {Esc}
Sleep 1000

WinActivate, ahk_id %bottomRight%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Left}{Down}{Lwin up}
Sleep 1000
Send {Esc}

WinActivate, ahk_id %bottomLeft%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Right}{Down}{Lwin up}
Send {Esc}
Sleep 1000

注意:根据需要在命令之间拨弄或添加
Sleep
,以优化脚本的可靠性。

感谢您的帮助。我复制了脚本并更改了一些内容,现在效果非常好。@led_pat,如果此解决方案解决了您的问题,请您将其标记为已接受的答案,以便其他人知道此问题已解决?