1)首先假设ini文件中存在这样的字符段 ? ?

    [hotstr] ;该段落为热字符串执行程序部分
    wd=winword.exe
    
    [replacetxt] ;该段落为热字符串替换超长文本部分
    dz=中国江苏省常州市钟楼区人民政府

?

?

2)在ahk中代码这样设置

思路:先逐一读取ini内容(对程序执行和文本替换分开执行读取),将热字符串与对应命令(或者对应替换文本)存储到新的二维数组中,然后采用hotstring函数逐一设置对应的标签,当然对应的标签需要采用循环来判断当前的hotstring是否存在对应;

注:hotstring函数在V1.28+的版本中为内置函数。离线帮助文件中可能没有该函数的内容。

?

g_hotstringext="+" ;这个作为一个直接运行的标记,实际使用中不是靠这个字符来判断,而是靠前面增加:X*:的前缀来直接运行。增加这个hotstring标记的目的是防止输入的时候误触发;
hotstring("reset") ;首先重置热字符串,hotstring函数在1.28+以后的版本内置。
read_section("hotstr") ;读取ini中hotstr段落的全部设置内容
;设置一个循环来逐一设置
;该段为热字符串运行程序
hoststr_count:=1
    ;写入热字符串对应代码
    while, (hoststr_count <= ar._maxindex()) ;这个ar数组实在readsection函数中的全局数组变量,读取后自动存储。
    {
            str1:= ar[a_index,1] . g_hotstringext ;这里面的g_hotstring
            StringSplit, hotstring_cmd_temp, % ar[a_index,2],"|"
            str2:= hotstring_cmd_temp1
            
        if (str1 <> "X" . g_hotstringext ) and ( str1 <> g_hotstringext) ;判断是否为分隔符或者是空值(注意带分隔符来判断)
        {    
            g_hotstringexec[a_index,1]:=":*:" . str1 ;采用新数组储存热字符串,这里原来代码采用的是:X*:这样的,可能是误写,应该只要:*:就可以自动触发了。
            g_hotstringexec[a_index,2]:=str2 ;储存对应运行命令
            hotstring(g_hotstringexec[a_index,1],"runhotstring") ;对应运行程序的runhotstring标签
         }
            hoststr_count+=1
    }
 
;设置一个新循环
;该段为热字符自动替换长文本;回车用`r`n来表示
read_section("replacetxt")
;重新赋值循环判断次数
hoststr_count:=1 
    ;写入热字符串对应代码
    while, (hoststr_count <= ar._maxindex()) ;数组同前
    {
            str1_a:= ar[a_index,1] . g_hotstringext
            str2_a:= ar[a_index,2]
            
        if ( str1_a <> g_hotstringext) ;判断是否为空值(注意带分隔符来判断)
        {    
            
            g_hotstringtext[a_index,1]:=":X*:" . str1_a ;储存热字符串,
            StringReplace,str2_a, str2_a, ``r``n, `n, All ;替换回车符
            ;StringReplace,str2_a, str2_a, ``n, `n, All ;替换回车符
            g_hotstringtext[a_index,2]:=str2_a ;储存对应替换文本
            hotstring(g_hotstringtext[a_index,1],"runhotstring_text") ;对应替换文本的runhotstring_text(不同于上面一个标签)
            
        }
            hoststr_count+=1
    }
return
;*********************************************
;热字符串跳转标签的执行段落(开始)
;*********************************************
;该段落为读取ini中的热字符串命令执行(执行程序)
runhotstring:
loop , % g_hotstringexec._maxindex() ;该数组中已经存储了读取的热字符串启动程序的内容,1位为热字符串,2位为对应程序路径
{
    if (a_thishotkey = g_hotstringexec[a_index,1]) ;a_thishotkey为内置变量,对应表示当前的热字符串
    {
        run, % g_hotstringexec[a_index,2],,UseErrorLevel
        EmptyMem()
        break ;运行成功后便推出循环
        return
    }
}
return
;该段落为读取ini中的热字符串命令执行(自动文本替换)
runhotstring_text:
loop , % g_hotstringtext._maxindex()
{
    if (a_thishotkey = g_hotstringtext[a_index,1])
    {
        Clipboard:=g_hotstringtext[a_index,2]
        send ^v ;采用发送粘贴快捷键显示效果最好,用send %txt%这样的形式会出现逐一跳出的视觉卡顿现象。
        EmptyMem()
        break
        return
    }
}
return
;*********************************************
;热字符串跳转标签的执行段落(结束)
;*********************************************

?