AutoHotkey Community

It is currently May 26th, 2012, 11:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: November 11th, 2009, 11:23 pm 
Offline

Joined: May 30th, 2009, 7:38 pm
Posts: 7
I have a macro taking information from a web page, you hit the start the macro and the first thing it does is:

Code:
Send, {CTRLDOWN}ac{CTRLUP}
clip_save := clipboard


Then it processes the information and creates a GUI with the information, I also have another macro that starts the same way, then processes the text and goes to another web page based on the text. Both hotkeys screw up probably about 1 out of 20 times, the copy won't go through and it will try using whatever was last on the clipboard.

So really all I'm asking with all that is, is there a more reliable way to copy text? This happens with both normal Send and SendInput modes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 12:35 am 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
I'm guessing because you don't show the relevant code to determine your problem.

It may be that the web page/s you are interacting with are NOT LOADED.
before you send your hotkeys. Since the loading time can vary.

If this is the case, search the forum for "web page is loaded", it's
been solved many times.

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 1:16 am 
Offline

Joined: May 30th, 2009, 7:38 pm
Posts: 7
Thanks for your reply, and sorry, I can see how you might have come to that conclusion since I did not give enough information. The rest of the code is pretty irrelevant though, and I'm beginning to think it's the computer instead of AutoHotKey.

Let me show you one of my testing scripts:

Code:
!k::
Send, ^a^c
clip_save := clipboard
MsgBox % clipboard
Reload
Sleep, 1000
MsgBox, "Syntax Error, script did not reload."
Return


(I also tried putting a full 1 second pause inbetween the CTRL+A and CTRL+C and it still had the same problem)

I can do this on a fully loaded page:

Copy a random block of text somewhere on the page, hit ALT+K, it will send the entire page to the message box, hit okay, copy a random block of text on the page again, hit ALT+K again, and continue... after about 5~20 times the message box will appear with the block of text I copied instead of the entire web page. The entire web page will be selected however, so the CTRL+A obviously went through, meaning the command didn't get skipped either.

Does that sound like it's my computers problem? That's all I could come up with, and it leaves me at another questions, is there a different way to copy the information?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 1:51 am 
after ^c, put ClipWait
check help file for more information


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 2:27 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Same problem on my pc (XP, Firefox, AutoCopy)

utilael wrote:
(I also tried putting a full 1 second pause inbetween the CTRL+A and CTRL+C and it still had the same problem)


I put a Sleep after ^c, & no more problem!

Maybe..
Code:
!k::
  Send ^a
  Sleep, 250
  Send ^c
  Sleep, 250
  clip_save := clipboard
  MsgBox % clip_save
  Reload
  Sleep, 1000
  MsgBox, "Syntax Error, script did not reload."
Return

This seems to work without error


Last edited by a_h_k on November 12th, 2009, 3:40 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 3:19 am 
Offline

Joined: October 9th, 2006, 8:19 pm
Posts: 236
Location: Finland
Quote:
after ^c, put ClipWait

And before ^c, empty Clipboard:
Code:
!k::
Clipboard =
Send, ^a^c
ClipWait, 5 ; Wait max 5 seconds
If ErrorLevel
{
    MsgBox, The attempt to copy text onto the clipboard failed.
    Return
}
...

_________________
Pekka Vartto


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 6:36 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Adding Sleep and/or ClipWait is the way to go, the reason is this: Send only sends the keystrokes to an application, it doesn't know what those keystrokes mean to that application nor when that application is done processing those keystrokes.

So when you send this:

Code:
Send, {CTRLDOWN}ac{CTRLUP}


AHK doesn't know those keystrokes are telling the application to select all and copy, nor does it know to wait until that application has finished selecting all and copying to proceed. That's why one out of twenty times you run this:

Code:
Send, {CTRLDOWN}ac{CTRLUP}
clip_save := clipboard


You sometimes get the old clipboard contents. AHK sent the keystrokes as it was told, once it was finished it proceeded to save the current contents of the clipboard to the variable...but the application hadn't finished selecting all and copying before AHK saved the clipboard to the variable. Nothing told AHK to wait, so it didn't.

ClipWait would probably be a more reliable delay than Sleep, since ClipWait will wait until the Clipboard's contents change before proceeding.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 9:18 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Also, if you want even more reliability, have the script compare the clipboard contents to what they were before you pressed ^c.

If they are the same, blank, or in a format you are not expecting, you can have it repeat the task, or do something else.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, Leef_me, patgenn123, Pulover, rbrtryn, XstatyK and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group