Autohotkey 如何在一个位置使用多个带特殊字符的热字符串?
要将l2r扩展到$L^2(\Bbb{R})$,我使用Autohotkey 如何在一个位置使用多个带特殊字符的热字符串?,autohotkey,Autohotkey,要将l2r扩展到$L^2(\Bbb{R})$,我使用 :*:l2r::$L^2(\Bbb{R})$ 然而,它总是扩展到 $L(\BbbR)$ 我不明白。为什么会这样?逗号、分号和其他字符,如{}^!+#在AHK中具有特殊含义,需要转义,以便以不同于通常的方式进行解释。看 发送此类文本或长文本的最简单、最快速的方法是: :*:l2r:: ClipSaved := ClipboardAll ; save clipboard clipboard := ""
:*:l2r::$L^2(\Bbb{R})$
然而,它总是扩展到
$L(\BbbR)$
我不明白。为什么会这样?逗号、分号和其他字符,如{}^!+#在AHK中具有特殊含义,需要转义,以便以不同于通常的方式进行解释。看 发送此类文本或长文本的最简单、最快速的方法是:
:*: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
逗号、分号和其他字符,如{}^!+#在AHK中具有特殊含义,需要转义,以便以不同于通常的方式进行解释。看 发送此类文本或长文本的最简单、最快速的方法是:
:*: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
如果我正确理解“立即压缩类似字符串”的含义,您可以尝试以下方法:
:*: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 text.ahk)中,并将其包含在主脚本的自动执行部分:
我的文本。ahk:
text1 =
(
text1_line1
text1_line2
)
text2 =
(
text2_line1
text2_line2
text2_line3
)
main 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
}
如果我正确理解“立即压缩类似字符串”的含义,您可以尝试以下方法:
:*: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 text.ahk)中,并将其包含在主脚本的自动执行部分:
我的文本。ahk:
text1 =
(
text1_line1
text1_line2
)
text2 =
(
text2_line1
text2_line2
text2_line3
)
main 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
}
使用第一种方法的优点是什么?为什么它比单纯的SendRaw快?SendRaw在某些程序中可能不起作用。剪贴板方法要快得多(几乎是即时的),尤其是当你必须发送一个长文本时。如何一次压缩类似的字符串,以便我只需要在一个地方使用
SendRaw
或ClipSaved
?请参阅我的下一个答案。使用第一种方法的优点是什么?为什么它比单纯的SendRaw快?SendRaw在某些程序中可能不起作用。剪贴板方法的速度要快得多(几乎是即时的),尤其是当你必须发送一个长文本时。如何一次压缩类似的字符串,因此,我只需要在一个地方使用SendRaw
或ClipSaved
?参见我的下一个答案。我可以将SendText
模块放在mytext.ahk
脚本中,然后将其包含在主脚本中吗?将函数定义添加到自动执行部分不是最佳做法,除非是脚本的开始或执行所必需的。就我个人而言,我更喜欢将我的功能放在一个目录中,以便同一目录中的其他脚本可以使用它们。我可以将SendText
模块放在mytext.ahk
脚本中,然后将其包含在主脚本中吗?将函数定义添加到自动执行部分不是最佳做法,除非是脚本的开始或执行所必需的。就我个人而言,我更喜欢将我的功能放在一个目录中,以便同一目录中的其他脚本可以使用它们。