Ooker
Ooker

Reputation: 3002

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

To expand l2r to $L^2(\Bbb{R})$ I use

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

However it always expands to

$L(\BbbR)$

I don't understand. Why is that?

Upvotes: 0

Views: 259

Answers (2)

Relax
Relax

Reputation: 10543

Comma, semicolon, and other characters such as {}^!+# have special meaning in AHK and need to be escaped in order to be interpreted differently than it normally would. See EscapeChar.

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

The easiest and fastest way to send such a text or a long text is this:

:*: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

Try also:

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

Upvotes: 1

Relax
Relax

Reputation: 10543

If I understand correctly what you mean by "compact similar strings at once" you can try something like this:

:*: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
}

OR

Put all your texts in a second script (My texts.ahk) in the same directory as your main script and include it in the auto-execute section of the main script:

My texts.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
}

Upvotes: 1

Related Questions