0
votes

I need Autohotkey (AHK) to insert text, enclosed within brackets, into my text files. However, my AHK code results in erroneous text input depending on using the code on text files opened in Notepad3 or opened in Emacs. My use of brackets are obviously wrong relative to the AHK syntax.

My minimum working example:

::ttt::  

    ; define variables
    myString = abcdf
    myFile   = C:\Users\myUser\notes\myFile.tex

    ; write variables into current file
    SendInput, <<%myString%>> {enter}
    SendInput, [[%myFile%]]  

return

The results I need should look like this:

<< abcde>>

[[C:\Users\myUser\notes\myFile.tex]]

Emacs When using this script on a text file opened with Emacs, the result looks like this:

<< abcde>>

[[C:\Users\myUser\notes\myFile.tex]]]

The first line written the way I need it, while the second line has got an extra "]" added in the end.

Notepad3 When using this script on a text file opened with Notepad3, the result looks like this:

<< abcde>>

[[C:\Users\myUser\notes\myFile.tex]]< /abcde>

The first line is written the way I need it, while the second line has got a variant of the first line added in the end, though with an "/" added.

How can I modify my code so the text input will look correct both in Notpad3 and in Emacs?

1
On my system there is no such issue. The result looks as it should be. Try your example first of all in a stand-alone script. - user3419297
Thanks for testing. My minimum working example above IS my stand-alone script. It behaves as I have shown - myotis

1 Answers

0
votes

Is the space in << abcde>> necessary? The definition of your variable doesn't seem to reflect that.

Nonetheless, the issue likely stems from the fact that these keys are being inputted instead of sending the text directly. I find that it's usually best to send strings as text if you wish to avoid other hotkeys from potentially disturbing your output. Try this adjustment:

SendInput {text}<< %myString%>>
SendInput {enter}
SendInput {text}[[%myFile%]]