8
votes

I've been trying to figure out how to insert/expand long text faster. The current keystroke method I'm using is quite time consuming and therefore something I would rather avoid.

Right now I am using the following method:

::abc::all bad cats

Or for longer text:

::li::
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

However the second method is a little slow.

Any suggestions for how I can avoid this slow expansion method? Perhaps by using the clipboard to copy and paste from the AHK script?

3

3 Answers

12
votes

Try this:

::li::
ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
clipboard := ""           ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
clipboard =               ; copy this text:
(
Lorem ipsum dolor ...
line2
..
)
ClipWait, 2              ; wait max. 2 seconds for the clipboard to contain data. 
if (!ErrorLevel)         ; If NOT ErrorLevel, ClipWait found data on the clipboard
    Send, ^v             ; paste the text
Sleep, 300
clipboard := ClipSaved   ; restore original clipboard
ClipSaved =              ; Free the memory in case the clipboard was very large.
return

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

2
votes
::li::  
text =
(
Line1
Line2
...
)
; IfWinActive, ahk_group textEditors ; create a group in the auto execute section
SendInput, %text%                      ;  SendInput is faster and more reliable
return

or

::li::
; IfWinActive, ahk_group textEditors
SendInput,
(
Line1
Line2
...
)
return
2
votes

Another Way to send Quickly long text with autohotkey Scripting languages is,

if you put all the text first to the Windows Registry Memory.

then you can Read it With [Registry Ram Memory Speed] to the [Clipboard Memory] paste it and it is done.

You can try this code:

Example1.ahk:

; [^ = Ctrl] [+ = Shift] [! = Alt] [# = Win]
#SingleInstance Force

;Variant 1
;put any clipboard text into variable a1
;send ^c
;a1=%clipboard%

;Variant 2
;or put any Variable to variable a1
;a1 := "Any Text"

;Variant 3
;or put any File text to variable a1
FileRead, a1, C:\My File1.txt
FileRead, a2, C:\My File2.txt

;Write the variable's To Registry - KeyHintText,value1 to value2
RegWrite, REG_SZ, HKEY_CURRENT_USER, software\KeyHintText,value1,%a1%
RegWrite, REG_SZ, HKEY_CURRENT_USER, software\KeyHintText,value2,%a2%

:*:abc:: 
clipboard := a1
send ^v
return

:*:def:: 
clipboard := a2
send ^v
return

Note - :*:abc:: = (you can type abc without Space) - ::abc:: = (you can type abc with Space)

If you use Windows Registry then the pros are :

1 - If the Value1 Text In the Registry is CHANGED, you use it with the same Hotkey :*:abc::

:*:abc:: 
RegRead, clipboard, HKEY_CURRENT_USER,software\KeyHintText,value1
send ^v
return

2 - If you Restart the Computer, all the Text is automatic Saved to the Ram Memory.

You can then only use this Code

example2.ahk

; [^ = Ctrl] [+ = Shift] [! = Alt] [# = Win]
#SingleInstance Force

;read the Variable's From Windows Registry
RegRead, a1, HKEY_CURRENT_USER,software\KeyHintText,value1 
RegRead, a2, HKEY_CURRENT_USER,software\KeyHintText,value2

:*:abc:: 
clipboard := a1
send ^v
return

:*:def:: 
clipboard := a2
send ^v
return

Tip: I use it With Buttoncommander Software you can then make on the Windows Desktop a set of Clickable Pictures (toolbars), you can replace for example the abc text into Pictures, if you push these Images With your Mouse or touch device it will Execute (native) the Autohotkey Command Codes.