使用Autohotkey 自动化打开浏览器到指定位置

31 阅读1分钟

下载 AutoHotkey(Windows 免费自动化工具)

  1. 官方下载地址官网下载:www.autohotkey.com/ 建议下载最新v2.x版本 image.png

  2. 下载后安装到用户目录

image.png

  1. 创建脚本

image.png

image.png

  1. 创建后会在指定文件目录下生成ahk文件

image.png

在ahk文件上编写指定脚本

  1. 例如: 在不同屏幕上启动两个网页
; 获取扩展屏的精确坐标(需根据实际情况调整)
secondaryScreenX := 3840
secondaryScreenY := 0
secondaryScreenWidth := 1920
secondaryScreenHeight := 1080

; 使用 Windows API 强制移动窗口
MoveWindowToScreen(WinTitle, x, y, w, h) {
    hwnd := WinExist(WinTitle)
    DllCall("SetWindowPos", "Ptr", hwnd, "Ptr", 0, "Int", x, "Int", y, "Int", w, "Int", h, "UInt", 0x40)
    DllCall("ShowWindow", "Ptr", hwnd, "Int", 9)  ; SW_RESTORE = 9
}

; 打开第一个窗口并移动到主屏幕
Run, chrome.exe --new-window "https://example.com"
WinWait, ahk_exe chrome.exe
MoveWindowToScreen("ahk_exe chrome.exe", 0, 0, 3840, 2160)  ; 主屏幕坐标 (0, 0)

; 打开第二个窗口并移动到扩展屏幕
Run, chrome.exe --new-window "https://example.com"
WinWait, ahk_exe chrome.exe
MoveWindowToScreen("ahk_exe chrome.exe", secondaryScreenX, secondaryScreenY, secondaryScreenWidth, secondaryScreenHeight)  ; 扩展屏幕坐标 (3840, 0)
  1. 启动时候需要未开启其他网页,则可以达到预期效果