Reputation: 3713
In Autohotkey program, is it possible to "paste" text content without having to use the clipboard?
I know I can simply use Send or simulate keystrokes but this causes an issue w/ my IDE's auto-complete feature.
I tried using Clipboard method and send a "paste" command but this is also causing issues since i have to save my current clipboard contents etc(too long to explain, not relevant to my question.)
I went thru the docs and i can't seem to find anything on this matter and I was wondering if you guys know of the answer?
Regards
Upvotes: 2
Views: 2454
Reputation: 1450
You don't have many options when it comes to this, but you do have some.
Options:
Most of the time Clipboard is the way to go as you will have no data loss when using ClipboardAll
Not all programs/Editors will let you use ControlSetText so that may not be an option you can use but if you're IDE's Edit Control is a standard windows control you maybe able to use it
Last option I can't say as we don't know the program you are trying to do this with...
Tutorial on making a simple multi Clipboard snippet's holder
Upvotes: 0
Reputation: 55
To my knowledge there isn't any sort of internal clipboard in AHK. And using commands such as ControlGetText
are going to be buggy if you have anything other than text, or if you want to preserve formatting.
This is the way that I've usually accomplished this sort of task.
#+c::
oCB := ClipboardAll ; save clipboard contents
Send, ^c
ClipWait,1
SplashTextOn, 160, 20, Clipboard, New Clipboard Copied
Sleep 2000
SplashTextOff
Return
;Now, pressing Control-V pastes the new text, and can be used as often as desired
#v:: ;And pressing Windows-V copies the old back to the clipboard
ClipBoard := oCB ; return original Clipboard contents
ToolTip, Old Clipboard `nRestored
Sleep 1000
ToolTip
oCB := ;Clears variable
Return
This is bascially what lintalist was referring too. But by using the variable ClipboardAll
you should be able to save anything to the clipboard, including formatting, images, etc.
Check out http://www.autohotkey.com/docs/misc/Clipboard.htm for more info on this command.
Also, shout out to pajenn on the AutoHotKey forums for the seed of this code. http://www.autohotkey.com/board/topic/39280-get-selected-text/
Upvotes: 1
Reputation: 383
(Same as Oq01 can't comment yet) If you don't want to use the clipboard because you want to restore the original clipboard content you can use the suggestion from the http://ahkscript.org/docs/misc/Clipboard.htm#ClipboardAll page: store the current clipboard contents in a variable, update your clipboard, paste it and restore the original content.
Perhaps your IDE supports multiple clipboards, a clipboard history or tag list which you can make use of as well if macros or scripting from within the program is possible.
Upvotes: 0
Reputation: 157
I would rather comment on the question but don't have enough points...
If the IDE supports code snippets. Maybe have Autohotkey (AHK) create a temp snippet in the IDE. Send the command to insert this temp snippet, and then delete the temp snippet. Messy solution but may work.
Upvotes: 0