Clouds Posted January 24, 2007 Posted January 24, 2007 (edited) Hey all! I've ran into a little problem... In the script below I try to select all text from a textarea, then copy it, and finally write the clopied text to a file. Normally this works fine. However, when the textarea contains a lot of text the script reaches 'ClipGet()' before Windows is done copying... ;~ Click in the text area ControlClick ( "Untitled - Notepad", "", 15,) ;~ Select all text and copy it Send("^a") ;~ sleep(500) Send("^c") ;~ sleep(1500) ;~ Get text from clipboard $txt = ClipGet() ;~ Write text to file $file2 = FileOpen("test_paste.txt",2) FileWrite($file2,$txt) FileClose($file2) Is there a way to make the script wait for both ctrl-a and ctrl-c are really finished? Sometimes it takes up to 1.5 sec for copying to complete... Of course 'sleep(1500)' could be used, but since most times there is no need to wait, I prefer not to have the delay each time something has to be copied (this code will be in a loop...) I've searched AutoIt help and the forums for a hint, but couldn't find any. Does anyone have a suggestion that might lead to a solution? [edit] Just after this message was posted, I realized I might be able to do 'ClipGet()' in a loop until the clipboard returns something....looking into it... [/edit] Best regards, Clouds® PS: AutoIt rules! ;-) Edited January 24, 2007 by Clouds
Clouds Posted January 24, 2007 Author Posted January 24, 2007 Well this still doesn't work: ;~ Empty the clipboard ClipPut ("") $txt = "" ;~ Click in the text area ControlClick ( "Untitled - Notepad", "", 15,) ;~ Select all text and copy it Send("^a") sleep(1000) Send("^c") ;~ sleep(1500) ;~ Get text from clipboard While $txt = "" $txt = ClipGet() WEnd ;~ Write text to file $file2 = FileOpen("test_paste.txt",2) FileWrite($file2,$txt) FileClose($file2) Still looking for hints.... -- Clouds®
BrettF Posted January 24, 2007 Posted January 24, 2007 Try: ;~ Empty the clipboard ClipPut ("") $txt = "" ;~ Click in the text area ControlClick ( "Untitled - Notepad", "", 15) ;~ Select all text and copy it Send("^a") sleep(1000) Send("^c") ;~ sleep(1500) ;~ Get text from clipboard Do $txt = ClipGet() Until Not $txt = "" MsgBox (0, "", "Something was coppied") ;~ Write text to file $file2 = FileOpen("test_paste.txt",2) FileWrite($file2,$txt) FileClose($file2) I hope it helps Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Psibernetic Posted January 24, 2007 Posted January 24, 2007 couldnt u just use $txt=ControlGetText("","",$EditBox) $file2 = FileOpen("test_paste.txt",2) FileWrite($file2,$txt) FileClose($file2) [sup]Psibernetic[/sup]My Creations:X-HideSecuracy
MHz Posted January 24, 2007 Posted January 24, 2007 You can do it another way Run('notepad') WinWait('Untitled') ControlSetText('Untitled', '', 'Edit1', 'Some text sent to the edit control') $txt = ControlGetText('Untitled', '', 'Edit1') MsgBox(0, 'Text', $txt)
Clouds Posted January 24, 2007 Author Posted January 24, 2007 Thanks for your comments all! Bert's solution works good...and it turns out that my solution does too... I tested both first with a real *big* text to be copied, to make sure the loop will do its job. Yet it seems to have exceeded windows clipboard limitations or so (the text couldn't even be copied by hand). So I concluded it didn't work, until I tried again with a smaller (yet stil large) text, and then both worked. The texts I work with aren't exceeding clipboard limits although they are large, so this looped ClipGet will do the job. Comment to the solution from Psibernetic and MHz...that works with the example given...but there's always a catch :-) The application I try to get text from, uses custom controls. The text area won't respond to 'ControlGetText', and AuInfo also shows no WindowText... But you didn't know that coz' I didn't tell it for sake of simplicity... So, thanks again for your efforts, and my apologies for bad testing...could have saved you some thinking and typing :-D -- Clouds®
BrettF Posted January 24, 2007 Posted January 24, 2007 Glad to be of asistance Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Psibernetic Posted January 24, 2007 Posted January 24, 2007 also glad to be of any help [sup]Psibernetic[/sup]My Creations:X-HideSecuracy
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