Reputation: 4660
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?
Upvotes: 8
Views: 14373
Reputation: 10636
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 ; don't change clipboard while pasting! (Sleep > 0)
clipboard := ClipSaved ; restore original clipboard
VarSetCapacity(ClipSaved, 0) ; free the memory in case the clipboard was very large.
return
If you often have to send such a complex or long text, you can create a function, for not repeating the whole code every time:
::li::
my_text =
(
Lorem ipsum dolor ...
line2
...
)
Send(my_text)
return
Send(text){
ClipSaved := ClipboardAll
clipboard := ""
clipboard := text
ClipWait, 1
If (!ErrorLevel)
Send, ^v
Sleep, 300
clipboard := ClipSaved
VarSetCapacity(ClipSaved, 0)
}
See ClipboardAll and ClipWait
Upvotes: 16
Reputation: 676
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.
Upvotes: 3
Reputation: 10636
::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
Upvotes: 3