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

如何用AutoHotkey (AHK)映射鼠标中键点击与拖动操作?

用AutoHotkey实现鼠标中键的映射(适配Gmail单手操作)

以下是针对你的需求编写的AutoHotkey脚本,可直接实现鼠标中键点击替换为Shift+左键点击,以及中键拖动替换为Ctrl+左键拖动,完美适配Gmail的单手操作场景:

完整脚本代码

#SingleInstance Force
#InstallMouseHook

; 鼠标中键点击 → Shift+左键点击;中键拖动 → Ctrl+左键拖动
$MButton::
    ; 记录初始鼠标位置,用于区分点击和拖动
    MouseGetPos, StartX, StartY
    ; 先按下Shift和左键,模拟点击前置状态
    Send {Shift Down}{LButton Down}
    
    ; 等待200ms,判断是否为短按点击(可根据习惯调整阈值)
    KeyWait, MButton, T0.2
    if ErrorLevel {
        ; 超过200ms未释放,判定为拖动:切换为Ctrl+左键拖动
        Send {Shift Up}
        Send {Ctrl Down}
        ; 等待中键释放,结束拖动
        KeyWait, MButton
        Send {LButton Up}{Ctrl Up}
    } else {
        ; 短按释放,判定为点击:完成Shift+左键点击动作
        Send {LButton Up}{Shift Up}
        ; 额外检查鼠标是否有移动,避免误判点击
        MouseGetPos, EndX, EndY
        if (Abs(EndX - StartX) > 5 || Abs(EndY - StartY) > 5) {
            Send {Ctrl Down}{LButton Down}
            Send {LButton Up}{Ctrl Up}
        }
    }
return

脚本说明

  1. 核心逻辑

    • 用$MButton::捕获中键事件,避免脚本自身触发循环
    • 通过KeyWait的超时判断区分「点击」和「拖动」:短按(<200ms)触发Shift+点击,长按触发Ctrl+拖动
    • 记录鼠标位置作为补充判断,防止轻微移动导致的误判
  2. 使用步骤

    • 安装AutoHotkey后,将上述代码复制到记事本,保存为.ahk后缀的文件(比如GmailMouseMap.ahk)
    • 双击运行脚本,右下角托盘出现AutoHotkey图标即生效
    • 如需开机自启,将脚本快捷方式放入系统启动文件夹(C:\Users\[你的用户名]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)
  3. 可选优化:限定仅在Gmail生效
    如果不想影响其他程序的中键功能,可给热键添加窗口限定(以Chrome为例):

    #SingleInstance Force
    #InstallMouseHook
    
    ; 仅在Chrome的Gmail窗口生效
    #IfWinActive, ahk_exe chrome.exe
    $MButton::
        MouseGetPos, StartX, StartY
        Send {Shift Down}{LButton Down}
        
        KeyWait, MButton, T0.2
        if ErrorLevel {
            Send {Shift Up}
            Send {Ctrl Down}
            KeyWait, MButton
            Send {LButton Up}{Ctrl Up}
        } else {
            Send {LButton Up}{Shift Up}
            MouseGetPos, EndX, EndY
            if (Abs(EndX - StartX) > 5 || Abs(EndY - StartY) > 5) {
                Send {Ctrl Down}{LButton Down}
                Send {LButton Up}{Ctrl Up}
            }
        }
    return
    #IfWinActive
    
  4. 参数调整

    • 可修改T0.2中的数值调整点击/拖动的判断阈值(单位:秒),比如T0.15对应150ms,适合点击更快的用户

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 15:55:13