Jump to content

Wait for text to be selected/copied


Clouds
 Share

Recommended Posts

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 by Clouds
Link to comment
Share on other sites

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®

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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®

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...