如何在一个地方使用多个带有特殊字符的热字符串?

How to use several hot strings with special characters at one place?

扩展l2r$L^2(\Bbb{R})$我用

:*:l2r::$L^2(\Bbb{R})$

但是它总是扩展到

$L(\BbbR)$

我不明白。这是为什么?

逗号、分号和其他字符(例如 {}^!+#)在 AHK 中具有特殊含义,需要进行转义才能以不同于正常情况的方式进行解释。参见 EscapeChar

:*:l2r::$L{^}2(\Bbb{{}R{}})$

发送此类文本或长文本的最简单、最快的方法是:

:*:l2r::
ClipSaved := ClipboardAll      ; save clipboard
clipboard := ""                ; empty clipboard
clipboard =                    ; send this text to the clipboard:
(
$L^2(\Bbb{R})$
)
ClipWait, 1                    ; wait for the clipboard to contain data
Send, ^v
Sleep, 300
clipboard := ClipSaved         ; restore original clipboard
return

也试试:

:*:l2r::
SendRaw,
(
$L^2(\Bbb{R})$
)
return

如果我理解正确 "compact similar strings at once" 的意思,您可以尝试这样的操作:

:*:st1::    ; Send text1
text =
(
text1_line1
text1_line2
)
SendText(text)
return

:*:st2::    ; Send text2
text =
(
text2_line1
text2_line2
text2_line3
)
SendText(text)
return

SendText(text){
    ClipSaved := ClipboardAll       ; save clipboard
    clipboard := ""                 ; empty clipboard 
    clipboard =  %text%             ; send this text to the clipboard:
    ClipWait, 1                     ; wait for the clipboard to contain data
    Send, ^v
    Sleep, 300
    clipboard := ClipSaved          ; restore original clipboard
}

将所有文本放入与主脚本相同的目录中的第二个脚本 (My texts.ahk) 中,并将其包含在主脚本的自动执行部分中:

我的texts.ahk:

text1 =
(
text1_line1
text1_line2
)

text2 =
(
text2_line1
text2_line2
text2_line3
)

主要script.ahk:

#NoEnv
#SingleInstance force
; ...
#Include %A_ScriptDir%\My texts.ahk
; ...
            RETURN   ; === end of auto-execute section ===

:*:st1::    ; Send text1
    SendText(text1)
return

:*:st2::    ; Send text2
    SendText(text2)
return


SendText(text){
    ClipSaved := ClipboardAll       ; save clipboard
    clipboard := ""                 ; empty clipboard 
    clipboard =  %text%             ; send this text to the clipboard:
    ClipWait, 1                     ; wait for the clipboard to contain data
    Send, ^v
    Sleep, 300
    clipboard := ClipSaved          ; restore original clipboard
}