AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reliability of Send, {CTRLDOWN}ac{CTRLUP};?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
utilael



Joined: 30 May 2009
Posts: 7

PostPosted: Wed Nov 11, 2009 10:23 pm    Post subject: Reliability of Send, {CTRLDOWN}ac{CTRLUP};? Reply with quote

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.
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Wed Nov 11, 2009 11:35 pm    Post subject: Reply with quote

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.
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
utilael



Joined: 30 May 2009
Posts: 7

PostPosted: Thu Nov 12, 2009 12:16 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Nov 12, 2009 12:51 am    Post subject: Reply with quote

after ^c, put ClipWait
check help file for more information
Back to top
a_h_k



Joined: 02 Feb 2008
Posts: 626

PostPosted: Thu Nov 12, 2009 1:27 am    Post subject: Reply with quote

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 Thu Nov 12, 2009 2:40 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
svi



Joined: 09 Oct 2006
Posts: 236
Location: Finland

PostPosted: Thu Nov 12, 2009 2:19 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Thu Nov 12, 2009 5:36 am    Post subject: Reply with quote

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.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
doyle



Joined: 14 Nov 2007
Posts: 325
Location: London, England

PostPosted: Thu Nov 12, 2009 8:18 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group