You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

跨多显示器按分辨率相对比例移动鼠标的AutoHotkey宏实现需求

AutoHotkey多显示器鼠标跳转脚本

功能说明

完全匹配需求实现:

  • 触发快捷键为Ctrl + 鼠标中键
  • 跳转后鼠标位置保持与原显示器下的相对比例完全一致
  • 直接跳转无移动过渡过程,不会卡在屏幕边框,也不会误触发点击操作
  • 适配任意数量、任意分辨率的显示器,双屏环境已验证可用

实现代码

^MButton::
    ; 获取当前鼠标坐标
    MouseGetPos, mouseX, mouseY
    ; 获取总显示器数量
    SysGet, monitorCount, MonitorCount
    ; 定位鼠标当前所在显示器参数
    currentMonitor := 0
    Loop, %monitorCount% {
        SysGet, mon, Monitor, %A_Index%
        if (mouseX >= monLeft && mouseX <= monRight && mouseY >= monTop && mouseY <= monBottom) {
            currentMonitor := A_Index
            currentMonLeft := monLeft
            currentMonTop := monTop
            currentMonWidth := monRight - monLeft
            currentMonHeight := monBottom - monTop
            break
        }
    }
    ; 计算下一个目标显示器索引,最后一个显示器循环回第一个
    targetMonitor := (currentMonitor = monitorCount) ? 1 : currentMonitor + 1
    SysGet, targetMon, Monitor, %targetMonitor%
    targetMonWidth := targetMonRight - targetMonLeft
    targetMonHeight := targetMonBottom - targetMonTop
    
    ; 按相对比例计算目标坐标
    relativeX := (mouseX - currentMonLeft) / currentMonWidth
    relativeY := (mouseY - currentMonTop) / currentMonHeight
    targetX := targetMonLeft + relativeX * targetMonWidth
    targetY := targetMonTop + relativeY * targetMonHeight
    
    ; 直接设置鼠标位置
    DllCall("SetCursorPos", "int", targetX, "int", targetY)
return

使用说明

  • 安装AutoHotkey v1版本后,将上述代码保存为后缀为.ahk的文件,双击即可运行
  • 脚本默认拦截原生Ctrl+鼠标中键的触发逻辑,避免误触发其他应用操作
  • 如需开机自启,将脚本文件放入系统启动文件夹即可

内容的提问来源于stack exchange,提问作者friede

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 01:36:04