Win F1~F12 快捷键回复

由于有需要 多次回复重复内容的需求
所以开发了此软件(基于AHK)
第一次发布有不足还望指点
不甚感激

#Requires AutoHotkey v2.0
#SingleInstance Force

configFile := A_ScriptDir "sobani.ini"

configGui := Gui(, "www..cn-sobani")
configGui.SetFont("s10", "Microsoft YaHei")

texts := []  ; 存储每个 F1-F12 的文本
edits := []  ; 存储 GUI 输入框

Loop 12 {
    key := "F" A_Index
    texts.Push(IniRead(configFile, "Hotkeys", key, ""))
}

; 创建 12 个输入框
Loop 12 {
    row := Ceil(A_Index / 4)
    col := Mod(A_Index - 1, 4) + 1

    xPos := 20 + (col - 1) * 180
    yPos := 30 + (row - 1) * 40

    configGui.Add("Text", "x" xPos " y" yPos - 15 " w160", "F" A_Index " 文本:")
    edits.Push(configGui.Add("Edit", "x" xPos " y" yPos " w160 h25", texts[A_Index]))
}

; 添加复选框:是否自动回车
autoEnter := IniRead(configFile, "Settings", "AutoEnter", "0")  ; 读取配置
autoEnterCheck := configGui.Add("CheckBox", "x150 y155 w250", "自动回车 (发送文本后按 Enter)")
autoEnterCheck.Value := autoEnter  ; 设定复选框状态

; 添加保存按钮
configGui.Add("Button", "x20 y150 w100 h30", "保存配置").OnEvent("Click", saveConfig)

configGui.Show("w750 h200")

; **保存配置函数**
saveConfig(*) {
    global edits, configFile, autoEnterCheck

    Loop 12 {
        key := "F" A_Index
        IniWrite(edits[A_Index].Value, configFile, "Hotkeys", key)
    }

    ; 保存自动回车选项
    IniWrite(autoEnterCheck.Value, configFile, "Settings", "AutoEnter")
    autoEnter := autoEnterCheck.Value  ; 更新全局变量

    MsgBox("配置已保存!", "成功", "Iconi T1")
    Reload  ; 重新加载脚本
}

; **✅ 绑定独立的热键,确保 F1-F12 输出各自文本**
Loop 12 {
    key := "F" A_Index
    thisText := texts[A_Index]  ; **把文本赋值到局部变量,确保每个按键独立**
    
    if thisText != "" {
        Hotkey(key, BindKey(thisText))
    }
}

; **✅ 使用独立闭包**
BindKey(text) {
    return (*) => SendWithEnter(text)  ; 发送文本并判断是否加回车
}

; **✅ 发送文本并判断是否加回车**
SendWithEnter(text) {
    global autoEnter
    SendText(text)  ; 发送文本
    if autoEnter  ; 如果开启了自动回车
        Send("{Enter}")  ; 发送回车
}

A_TrayMenu.Add()  ; 创建分隔线.
; 添加右键菜单
A_TrayMenu.Add("打开配置", OpenGui)  ; 右键菜单添加打开配置选项
A_TrayMenu.Add("切换自动回车", ToggleAutoEnter)  ; 添加切换自动回车选项
A_TrayMenu.Add("退出", ExitScript)  ; 添加退出脚本选项

Persistent

; **切换自动回车模式**
ToggleAutoEnter(*) {
    global autoEnter, configFile
    autoEnter := !autoEnter  ; 取反
    IniWrite(autoEnter, configFile, "Settings", "AutoEnter")  ; 更新配置文件
    TrayTip("", autoEnter ? "开启自动回车" : "关闭自动回车", 1)
}

; 打开 GUI 函数
OpenGui(*) {
    configGui.Show("w750 h200")  ; 显示配置界面
}

; 退出脚本函数
ExitScript(*) {
    ExitApp  ; 退出脚本
}

https://wwps.lanzouu.com/iFd2A2s8v1zg

密码:hshd

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 共3条

请登录后发表评论