执行热键时缺少字符

Missing characters when executing hotkey

我正在编写一个热键快捷方式以在 Wordpress 中突出显示文本。代码是这样的:

^f2::
Send, ^x [su_highlight background="#DDFF99" color="#008000" class=""] ^v [/su_highlight]
return

然而,当我在一个字符串上执行它时,我们称它为 string1,它 returns

[su_highlight background="DDFF99" color="08000" class=""] string1 [/su_highlight].

任何人都可以解释为什么“#”消失以及颜色 0 之一消失,我可以做些什么来解决它?

提前致谢!

这是因为'#'在使用'Send'时被当作Windows键,所以需要转义

来自The #EscapeChar Documentation page

When the Send command or Hotstrings are used in their default (non-raw) mode, characters such as {}^!+# have special meaning. Therefore, to use them literally in these cases, enclose them in braces. For example: Send {^}{!}{{}.

因此,修改后的代码为:

^f2::
Send ^x [su_highlight background="{#}DDFF99" color="{#}008000" class=""] ^v [/su_highlight]
return

编辑:或者,如果您不想在每次要键入文字#(或其他受影响的字符)时更改某些字符,则可以改用 SendRaw 命令。

例如:

对命令和文本使用单独的发送

^f2::
Send ^x
SendRaw [su_highlight background="#DDFF99" color="#008000" class=""] 
Send ^v 
SendRaw [/su_highlight]
return

有关 SendRaw 的更多信息,请点击此处 the Documentation link for SendRaw

为了补充另一个答案,我会推荐 Text mode as opposed to any other mode. Because it can be used in combination with SendInput,这是推荐的更快、更可靠的发送模式。

所以:

^F2::
    SendInput, ^x
    SendInput, {Text}[su_highlight background="#DDFF99" color="#008000" class=""] 
    SendInput, ^v 
    SendInput, [/su_highlight]
return

不过,通过发送命令发送的时间开始有点长(在我看来)。
考虑更多地使用剪贴板以获得更快、更可靠的选项:

^F2::
    Clipboard := "" ;empty the clipboard first
    
    ;send ctrl+x (cut), ctrl+v could be used in most text editors as well
    SendInput, ^x
    
    ;wait for the clipboard to contain something
    ;this is not required and it will likely work without it
    ;but it's kind of recommended I guess
    ClipWait 
    
    ;set the clipboard to contain what we want
    Clipboard := "[su_highlight background=""#DDFF99"" color=""#008000"" class=""""]" Clipboard "[/su_highlight]"
    
    ;send ctrl+v
    SendInput, ^v 
return