2
votes

I want to write an Autohotkey text to edit the text that the user selects and append four spaces at the beginning of every line.

If I would simply have a string with multiple lines the task would be easy.

I googled and found one solution at the official Autohotkey forum. That solution copies the text into the clipboard potentially deleting the clipboard content.

Is there a way to do this in autohotkey that doesn't use the clipboard where I can directly operate on the selected text?

1
Getting the text from a control is certainly possible. What control, though? You don't actually say. If the control is a web page edit box, for example, AHK lets you access the DOM and you can use selectors to get at the element and its content. But if you are worried about using the clipboard, why don't you just store the present contents and then do your thing and then restore the clipboard from the saved variable? - PGilm
@PGlim : Basically the DOM that has focus. Does a Webpage has fundamentally different DOM's than they editing text in Evernote? Is it possible to access both in the same way? - Christian
Duplicate of previously asked quesiton: stackoverflow.com/questions/36067563/… (not answered though) - phil294

1 Answers

2
votes

Here are some basic Clipboard techniques:

ClipSaved := ClipboardAll   ;  Save the entire clipboard to a variable of your choice (in this case, ClipSaved).

;  Here is where you put your code

Clipboard := ClipSaved   ;  Restore the original clipboard.
ClipSaved =   ;  Free the memory in case the clipboard was very large.

More here: https://autohotkey.com/docs/misc/Clipboard.htm