dbzfanatic Posted November 19, 2008 Share Posted November 19, 2008 Well I've seen one too many "how do I avoid character by character sending to a control?" questions. Now people can simply point the new people to this topic.Func _ControlPaste($sCTitle,$sCText,$sCID,$sText) ClipPut($sText) ControlFocus($sCTitle,$sCText,$sCID) Send("^{V}") EndFuncWas that really so hard people? I mean seriously,come on... Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
ResNullius Posted November 19, 2008 Share Posted November 19, 2008 (edited) Well I've seen one too many "how do I avoid character by character sending to a control?" questions. Now people can simply point the new people to this topic. Func _ControlPaste($sCTitle,$sCText,$sCID,$sText) ClipPut($sText) ControlFocus($sCTitle,$sCText,$sCID) Send("^{V}") EndFunc Was that really so hard people? I mean seriously,come on...Time for a rewrite: you didn't provide for the case where there is something already on the clipboard that needs preserving Edited November 19, 2008 by ResNullius Link to comment Share on other sites More sharing options...
dbzfanatic Posted November 19, 2008 Author Share Posted November 19, 2008 (edited) Fine how's this? Func _ControlPaste($sCTitle,$sCText,$sCID,$sText,$iPreserve) If $iPreserve = 1 Then $sCBText = _ClipBoard_GetData() Endif ClipPut($sText) ControlFocus($sCTitle,$sCText,$sCID) Send("^{V}") If $sCBText <> "" Then ClipPut($sCBText) Endif EndFunc Edit: Used _ClipBoard_GetData() to allow non-text clipboard preservation. Edited November 19, 2008 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
ResNullius Posted November 20, 2008 Share Posted November 20, 2008 (edited) Fine how's this? Func _ControlPaste($sCTitle,$sCText,$sCID,$sText,$iPreserve) If $iPreserve = 1 Then $sCBText = _ClipBoard_GetData() Endif ClipPut($sText) ControlFocus($sCTitle,$sCText,$sCID) Send("^{V}") If $sCBText <> "" Then ClipPut($sCBText) Endif EndFunc Edit: Used _ClipBoard_GetData() to allow non-text clipboard preservation. Better, but if you're making it a UDF, then for the nubes you need #include <Clipboard.au3> And I think I'd make $iPreserve default to 1 #include-once #include <Clipboard.au3> Func _ControlPaste($sCTitle, $sCText, $sCID, $sText, $iPreserve = 1) Local $sOldCBData = "" If $iPreserve = 1 Then $sOldCBData = _ClipBoard_GetData() EndIf ClipPut($sText) ControlFocus($sCTitle, $sCText, $sCID) ControlSend($sCTitle, $sCText, $sCID, "+{INSERT}") If $sOldCBData <> "" Then ClipPut($sOldCBData) EndIf EndFunc Also I changed to ControlSend from plain Send just for a added measure of reliability, and I send the Shift+Insert keycombo because sometimes sending Ctrl+V can be unpredicatable. Edited November 20, 2008 by ResNullius Link to comment Share on other sites More sharing options...
dbzfanatic Posted November 20, 2008 Author Share Posted November 20, 2008 (edited) Yeah sure just take over my project lol. Thanks for the help/suggestions though. My brain's been a bit fried lately (my girlfriend's parents went ballistic on us) so I appreciate the help, honestly.Edit: Did some testing (my head cleared a bit plus I'm bored) and I noticed that it does not preserve the data on the clipboard. I think I may revert it to saving only text instead of using _ClipBoard_GetData(), which I now see returns only handles and not the data itself.Edit 2: Here is the modified function that preserves clipboard text.#include-once #include <Clipboard.au3> Func _ControlPaste($sCTitle, $sCText, $sCID, $sText, $iPreserve = 1) If $iPreserve = 1 Then $sCBText = ClipGet() EndIf ClipPut($sText) ControlFocus($sCTitle, $sCText, $sCID) ControlSend($sCTitle, $sCText, $sCID, "+{INSERT}") If $sCBText <> "" Then ClipPut($sCBText) EndIf EndFuncHere is an example of the usage._ControlPaste("Untitled - ", "", "Edit1","Some text for Notepad.")Edit 3: Did a bit more reading and it seems ClipPut() clears the clipboard and then places the specified data onto it. I tried using _ClipBoard_SetData() but that requires a handle to the data,not the data itself. Retrieving the data with _ClipBoard_GetData() would return a handle but as soon as ClipPut() is called the handle is useless. I will work on this a bit and see if I can create a structure for the handle to the actual text, that way the handle to previous clipboard data remains. Edited November 20, 2008 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
wraithdu Posted November 20, 2008 Share Posted November 20, 2008 Here's what you need. I did these a while back -http://www.autoitscript.com/forum/index.php?showtopic=81267 Link to comment Share on other sites More sharing options...
dbzfanatic Posted November 21, 2008 Author Share Posted November 21, 2008 Thanks, I'm looking into them right now. They do seem to be what I need, I just need to do a bit of work on the implementation. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now