现有的很多 AI 智能体的聊天框的设计不支持 Ctrl + Enter 触发提交, 而是 Enter 直接提交信息. 这对中文用户来说可能不太友好, 比如我在中英混输时, 中间有个英文单词通过 Enter 上屏, 如果不小心误触两次 Enter, 会导致信息输入到一半就提交了.

下面提供一个基于 AHK 的解决思路, 请先下载 AutoHotkey V2 版本, 然后将下面的代码保存为 .ahk 脚本:

; 功能说明: 
; - RShift 将候选框字母上屏
; - 多次连击 RShift, 只会触发一次上屏操作 (解决了误触问题)
; - RCtrl 触发软换行 (相当于 Shift + Enter)

#Requires AutoHotkey v2.0

;RShift::Enter
RCtrl::+Enter

global blockNextRShift := false

; InputHook is used only while we are waiting to see
; whether another key is pressed before the next RShift.
global watcher := InputHook("V")
watcher.KeyOpt("{All}", "N V")
watcher.OnKeyDown := OnWatcherKeyDown

RShift::
{
    global blockNextRShift, watcher

    ; We already handled one RShift and no other key
    ; has appeared since then: swallow this RShift.
    if blockNextRShift
    {
        blockNextRShift := false
        watcher.Stop()
        return
    }

    ; First RShift.
    blockNextRShift := true
    Send "{Enter}"

    ; Start watching for the next physical key.
    watcher.Start()
}

OnWatcherKeyDown(ih, vk, sc)
{
    global blockNextRShift, watcher

    ; Right Shift = VK 0xA1.
    ;
    ; Do not clear the state for another RShift.
    ; The RShift hotkey above will deal with it.
    if vk = 0xA1
        return

    ; Any other key cancels the "block next RShift" state.
    blockNextRShift := false
    watcher.Stop()
}

将它们保存到 “no_ambiguous_chat_commit.ahk”, 然后运行.

如果需要停止: 在任务栏托盘区找到 AHK 的图标, 右键点击退出.

相关阅读: https://chatgpt.com/share/6a6ac6f9-1e50-83ee-b5b6-90e91b8c7f23

Logo

AtomGit AI 社区提供模型库、数据集、Agent、Token等资源

更多推荐